This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
vasprintf
- From: Mark Richards <mark dot richards at massmicro dot com>
- To: libc-help at sourceware dot org
- Date: Wed, 05 Aug 2009 20:37:15 -0400
- Subject: vasprintf
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