Skip to content

free the memory safely!! #8

Description

@GoogleCodeExporter
Chapter Darray

I use the MACRO SAFE_FREE(p) to free memory, but I want to test that 
wheather the memory was free safely or not. So when a darray was 
destroied, I still used darray_foreach() to print the darray. If you test 
it, you'll find that it still prints many integer numbers which are 
erratic. 

What is the expected output? What do you see instead?
I think when a darray is destroied, there are no numbers to print, because:
SAFE_FREE(thiz->data);
SAFE_FREE(thiz);
But in fact, many erratic numbers are printed.

Please provide any additional information below.
So I check the code. And fortunately, finally I found.
We use function free() to free memory safely
free() and malloc() must come in pairs.
The real memory area is thiz->data, so we free thiz->data and make the 
pointer thiz point to NULL. 
I think the above mentioned can avoid the problem.
Just like the following:

SAFE_FREE(thiz->data);
thix = NULL;

Original issue reported on code.google.com by gary.li....@gmail.com on 29 Apr 2010 at 6:54

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions