Given the following code:
int *a = NULL;
a = calloc(1, sizeof(*a));
printf("%d\n", a);
a = realloc(a, 0);
printf("%d\n", a);
return (0);
It returns:
4078904
0
Is this realloc equivalent to a free ?
NOTE:
I am using MinGW under WindowsXP.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Not necessarily.
It often does as with the link that munissor posted, but the Mac OS 10.5 man page says:
What is a “minimum sized object”? Well, any allocator stores some information about the allocations, and that takes space which is often allotted in addition to the space reserved for the user. Presumably a “minimum sized object” is just one of these headers plus zero bytes of space reserved for the user.
I would guess that this provision is present to support implementations that existed at the time of standardization, and that those implementations are useful for debugging allocation behavior.
To address Jonathan’s comments
Consider the difference between
and
With a sane implementation of
mallocandfreethe first clip does not consume memory without bound. But if thereallocimplementation returns those “minimum sized objects” it might.Certainly this example is contrived and it relies on understanding what is meant by “minimum sized object”, but I think that text allows it.
In short, if you mean
freeyou should sayfree.