#102 function wvFree is screwed

closed-fixed
nobody
None
5
2006-03-11
2003-04-16
No

Original function:

void wvFree (void * ptr)
{
if (ptr != NULL)
{
free (ptr);
ptr = NULL;
}
}

ptr=NULL never does anything, because the ptr passed
in is a copy of the original pointer, it aint the original
pointer. Calling wvFree to free a bit of memory leaves
your variable still pointing to that freed location. I know of
a couple of places where this causes wvFree to be
called twice for the same bit of memory, causing
SIGSEVs and GPFs.

Code should be:

void wvFree (void ** ptr)
{
if (*ptr != NULL)
{
free (*ptr);
*ptr = NULL;
}
}

You then need to change every call to wvFree to pass in
the address of your pointer. So instead of

wvFree (item->grpprl);

use

wvFree (&item->grpprl);

Discussion

  • Dom Lachowicz

    Dom Lachowicz - 2006-03-11
    • status: open --> closed-fixed
     
  • Dom Lachowicz

    Dom Lachowicz - 2006-03-11

    Logged In: YES
    user_id=69417

    This was fixed a while ago. Thanks.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks