Re: Adding a realloc() usage note to the malloc(3) manual page

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Paul,

On Thu, 2 Sept 2021 at 03:23, Paul Eggert <eggert@xxxxxxxxxxx> wrote:
>
> On 9/1/21 5:21 PM, Michael Kerrisk (man-pages) wrote:
> > Obviously, '*ptr' is invalid after a
> > successful realloc(). But why is 'ptr' invalid?
>
> The C standard says that once a program has freed a non-null pointer,
> the program cannot look at the pointer's value any more. It can't copy
> the value to another pointer, and it can't even test whether the value
> is null. A debugging implementation can trap any use of the pointer's value.

Thanks. I wondered if it was something like that, but there was
nothing obvious in the specification for free().

But, just to confirm, I suppose that you are talking about this
sentence (which I did finally discover) from Section 6.2.4 ("Storage
durations of objects") in the C11 standard:

[[
The value of a pointer becomes indeterminate when the object it points
to (or just past) reaches the end of its lifetime.
]]

?

> This rule is not an issue for production uses of glibc realloc. However,
> it could at least in theory affect debugging implementations like gcc
> -fsanitize=address, because the rule can help catch bugs in programs.
> And I vaguely recall talk that a few non-glibc platforms (IBM i,
> perhaps?) enforce the rule.

Thanks for the background.

Cheers,

Michael

-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/



[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux