Mail Archives: djgpp/1997/01/10/00:56:22
Dim Zegebart (zager AT post DOT comstar DOT ru) wrote:
: 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)
Both of them will work, however, since they both point to the same
allocated memory block, once it is freed neither pointer should be used
to reference (or free) the memory. (Both ptr1 and ptr2 should be set to
null be sure).
JL
- Raw text -