vasprintf

Mark Richards mark.richards@massmicro.com
Thu Aug 6 00:37:00 GMT 2009


Tracking down some memory leaks and need expert voice/s on vasprintf...


   linux 2.6.19 #9 PREEMPT Mon Apr 6 15:44:03 EDT 2009 cris
   (gcc-cris using glibc version (/usr/local/cris/lib/gcc-lib/cris/2.7.2/)

Reference code:

static char *SetCurrentProcess(char *fmt,...)
{
     char *ptr=NULL;
     va_list list;
     va_start(list,fmt);
     vasprintf(&ptr,fmt,list);
     va_end(list);

     if (!ptr)
     {
         printf("fail to allocate ptr\n");
         return("");
     }

     if (nProcStackIndex==PROCSTACK_SZ)
     {
         
snprintf(cCurrentProcName,PROCSTACK_SZ,"%s",procstack[nProcStackIndex]);
     }
     else
     {
         ++nProcStackIndex;
         snprintf(procstack[nProcStackIndex],PROCSTACK_SZ,"[%s]",ptr);
         
snprintf(cCurrentProcName,PROCSTACK_SZ,"%s",procstack[nProcStackIndex]);
     }
     free(ptr);
     return(procstack[nProcStackIndex]);
}



I'm using memwatch to help me locate the memory leaks.  memwatch issues 
the error:

    WILD free: <1> src/aemnet.c(1532), unknown pointer 0x1321f8

each time I free(ptr).


vasprintf() docs say to free the pointer.  Yet doing so seems to trigger 
this error.

So I'm thinking maybe the glibc version doesn't need free().  But how???

Thoughts?

/m



More information about the Libc-help mailing list