08-09-2006, 02:54 AM
Reference: http://www.cplusplus.com/ref/cstdlib/realloc.html
If realloc fails a null pointer will be returned, but is the original memory chunk freed?
In other words is it safe to do this:
Or do I have to do this to be sure to avoid memory leaks?:
EDIT:
see;http://www.c-faq.com/malloc/realloc.html
If realloc fails a null pointer will be returned, but is the original memory chunk freed?
In other words is it safe to do this:
Code:
int* pointer; pointer=alloc(sizeof(int)*10); pointer=realloc(sizeof(int)*100); free(pointer);
Code:
int* pointer;
int* ptmp;
pointer=alloc(sizeof(int)*10);
ptmp=realloc(sizeof(int)*100);
if (ptmp!=0) {
pointer=ptmp;
}
else {
free(pointer); //<------ free the original memory
//Other error handling
}
EDIT:
see;http://www.c-faq.com/malloc/realloc.html
/post]