Jump to content

FATAL: FreeRTOS Malloc Error!!! in MIOS32


m.str
 Share

Recommended Posts

I keep on receiving this error (topic title) in MIOS32 after switching between sections via my ngr script which proceeds to request store SysEx dumps from a connected synth.

I have a firm belief about what probably causes the error (the error I could not resolve by research, though.. the term malloc just leads me to think, that there is some memory that is not being freed properly after use)

What I did in my c files was introducing a new kind of variable (called ^macdis) for use in SysEx stream sending. What it does is that it resolves a value from a sysEx dump (identified by syxdump_pos:x:y) into a 6-field u8 array to be further used for sending it to a Mackie C4, which uses it to display the value on six fields of one of its displays. I herefore instanciate a u8[6] array here:

s32 MBNG_EVENT_SendSysExStream(mios32_midi_port_t port, mbng_event_item_t *item)
{
  u8 *stream_in = item->stream;
  u32 stream_size = item->stream_size;
  s16 item_value = item->value;
  //initialize array and pointer for the 6-field Display values
  u8 *macdis_array;
  macdis_array = (u8 *)malloc(sizeof(u8)*6);

.....

And I have a feeling that I just did not fully get my head around the whole pointer thing. After repeatedly calling my ngr section 1, which requests and receives the dump and subsequently uses the ^macdis flag to print one value on the mackie (and herefore using the array, which I want to be ONE array, that is cleared after the processing of one incoming value and then used for the next) the error comes up and the whole thing crashes of course. Here is how the (relevant part of) code in mbng_event.c goes on:

case MBNG_EVENT_SYSEX_VAR_MACDIS: {

          int i, j, rest;
          u8 num = item_value;

          for(i=5;i>=0;i--){
              if(i == 0 || i == 4 || i == 5){
              macdis_array = 0x2d;
              }
              else{
                  if(num > 0){
                                rest = num%10;
                                num /= 10;
                                switch(rest){
                                case 0: macdis_array = 0x30; break;
                                case 1: macdis_array = 0x31; break;
                                case 2: macdis_array = 0x32; break;
                                case 3: macdis_array = 0x33; break;
                                case 4: macdis_array = 0x34; break;
                                case 5: macdis_array = 0x35; break;
                                case 6: macdis_array = 0x36; break;
                                case 7: macdis_array = 0x37; break;
                                case 8: macdis_array = 0x38; break;
                                case 9: macdis_array = 0x39; break;
                                default: macdis_array = 0x2d; break;
                                }
                            }
                  else{
                      macdis_array = 0x30;
                  }
              }
          }
          for(j=0;j<6;j++){
              MBNG_EVENT_ADD_STREAM(macdis_array[j] & 0x7f);
          }
      } break;

 

 

Since I cannot resolve the error by reasearch I would be grateful for anyone, who might take a quick glance at my code. Maybe someone, who is a bit more experienced in C than I am might see the (possibly obvious) error

Link to comment
Share on other sites

Just a supershort comment:

for every malloc() there must be matching a free() otherwise you'll run out of heap memory at some point in time. So, do you'd need a call

free(macdis_array);

somewhere after you don't need to access this array any more. Btw. if it is always 6 bytes long, you can just skip the malloc (and free!) and use a variable on the stack:

u8 macdis_array[6];

Hope this helps - have fun and many greets!
Peter

Link to comment
Share on other sites

Hey Peter,

thanks for the reply. At this point, it seems solved! Interestingly enough the error still came up when I ttried the first approach

On 29.6.2020 at 5:38 PM, m.str said:

for(j=0;j<6;j++){
              MBNG_EVENT_ADD_STREAM(macdis_array[j] & 0x7f);
          }
      } break;

I inserted the free() call after this for loop, so after the array values had been processed and were no further used. This is what made the most sense to me. That the error still occured worries me a bit, because that MIGHT mean, that it's something else... On the other hand I tried your second approach by turning this

 

On 29.6.2020 at 5:38 PM, m.str said:

//initialize array and pointer for the 6-field Display values
  u8 *macdis_array;
  macdis_array = (u8 *)malloc(sizeof(u8)*6);

to this

//initialize array and pointer for the 6-field Display values
  u8 macdis_array[6];

and this is working at the moment. I hope it stays functional :)

Best wishes,

Micha

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...