This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: Can realloc be marked as a mallloc-like function?
> On Mon, Jul 16, 2007 at 02:39:39PM -0000, Wolfram Gloger wrote:
> > > int *p;
> > > p = malloc (4);
> > > *p = 0;
> > > p = realloc (p, 4);
> > > *p = 1;
> >
> > By that reasoning, consider:
> >
> > int *p;
> > p = malloc (4);
> > *p = 0;
> > free(p);
> > p = malloc (4);
> > *p = 1;
>
> Except that in the first sequence, the value of *p is retained across
> the reallocation, so "*p = 0" is not dead. The two examples aren't
> really the same at all.
I'm not saying they are the same. But, how does gcc determine that it
can move "*p = 0" after realloc()? Does it treat realloc() specially
and insert a run-time check to look at its result to compare it with
the old pointer? That would seem like a dubious feature totally
independent of __attribute_malloc__.
Surely you agree that in my second example, "*p = 0" _cannot_ be moved
after the call to destroy_something_and_allocate_anotherthing(p)?
Regards,
Wolfram.