OpenAT 4.11 leaks memory?


#1

Hello. I have found that, in OpenAT 4.11, whenever I use the adl_atCmdCreate() call, I lose 32 bytes of heap memory. I’m testing various things every second (signal strength, A/D levels, neighbouring GSM cells) and so, after about 2 hours, the application runs out of memory and the module resets.
I’d like to know if you can reproduce it with the following code (modification of Hello World), and if there’s a fix. It crashes around cycle 7808.

bool main_test_Handler(adl_atResponse_t *paras)
 {
  return FALSE;
 }

static int cycle=0;

void HelloWorld_TimerHandler ( u8 ID )
{
    ascii buff[100];
    /* Hello World */
    TRACE (( 1, "Embedded : Hello World" ));
    cycle++;
    wm_sprintf(buff, "\r\nCycle=%d\r\n", cycle);
    adl_atSendResponse ( ADL_AT_UNS, buff);
    adl_atCmdCreate("ATI", FALSE, main_test_Handler, "*", NULL);
}

I’m actually using a binary search (with adl_memGet/adl_memRelease) to find the exact amount of free memory, so I know that it’s 32 bytes for every call.

I wonder why no one has noticed this yet? This is pretty serious, IMHO.
My module returns

The memory also leaks in Debug mode, but the available memory there is over 1 MB, so it would take forever to wait for the crash.

Thanks in advance for any help,
Milan


#2

Sorry, I should have noticed it WAS already found under a different topic.

http://www.wavecom.com/modules/movie/scenes/forums/viewtopic.php?t=904&postdays=0&postorder=asc&start=0

Milan


#3

Hi,

OpenAT version 4.12 release note has stated that this issue has been resolved. Contact your distributor to get it.


#4

I’m interrested to have a sample of code to get Free Memory. Can you please post your example please ?


#5

It’s not very nice but it works.

bool testingMemory=false;

int computeFreeMemory()
 {
  int lo=0, hi=60000, base=0;
  void *many=NULL;
 
  testingMemory=true;

  do
   {
    void *many2=adl_memGet(60000);
    if (many2==NULL)
      break;;
    *(void **)many2=many;
    many=many2;
    base+=60000;
   }
  while (base<1100000); //in Debug more there can be really much memory sometimes

  while (lo<hi)
   {
    int mid=(lo+hi)/2;
    void *ptr=adl_memGet(mid);
    if (ptr==NULL)
      hi=mid;
    else
     {
      adl_memRelease(ptr);
      lo=mid+1;
     }
   }
  while (many!=NULL)
   {
    void *many2=*(void **)many;
    adl_memRelease(many);
    many=many2;
   }

  testingMemory=false; 

  return lo+base;
 }

If you have defined an error handler, add this at the beginning:

bool errorHandler(u16 ErrorID, ascii *ErrorStr)
 {
  if (testingMemory && (ErrorID==16))
    return FALSE;
  ...
 }

#6

Thanks !
It works :wink: