Mail Archives: djgpp/1997/01/09/20:33:12
In article <32D35994 DOT 43BD AT post DOT comstar DOT ru>, Dim Zegebart
<zager AT post DOT comstar DOT ru> writes
>Hi,
>
>Just a small question about free() function
>
>Let's :
>
>char *ptr1,*ptr2;
>
>ptr1=(char*)malloc(sizeof(char)*1024);
>if (ptr1!=NULL) ptr2=ptr1;
>...
>
>//so my question. May i use
>free(ptr2);
>//or i have to use
>free(ptr1)
Just use the latter, 'free(ptr1)'. As even though ptr2 has been set to
ptr1, ptr1 still points to the memory block you just allocated.
If you used the former, ptr1 would be NULL and ptr2 could be damn nearly
anything, but you wouldn't want to free a NULL pointer would you? <g>
--
Moo-Juice
- Raw text -