public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/12547] New: realloc(p, 0) violates C99
@ 2011-03-06 22:48 msebor at gmail dot com
  2011-03-11  1:11 ` [Bug libc/12547] " drepper.fsp at gmail dot com
                   ` (18 more replies)
  0 siblings, 19 replies; 20+ messages in thread
From: msebor at gmail dot com @ 2011-03-06 22:48 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=12547

           Summary: realloc(p, 0) violates C99
           Product: glibc
           Version: 2.13
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper.fsp@gmail.com
        ReportedBy: msebor@gmail.com


The C99 standard specifies that an implementation may return NULL from a call
to realloc(p, 0). However, in such a case a conforming implementation must
avoid freeing the space pointed to by p and a program must call free(p). The
test case below shows that glibc violates this C99 requirement, causing a
program to free the space twice. Note that this C99 requirement to avoid
freeing the pointer is in contrast to POSIX -- see the discussion on the
austin-group-l list starting with this post:
https://www.opengroup.org/sophocles/show_mail.tpl?CALLER=show_archive.tpl&source=L&listname=austin-group-l&id=15252

$ cat <<EOF | gcc -xc - && ./a.out 
#include <stdlib.h>

int main(void) {
    void *p, *q;

    p = malloc(1);
    q = realloc(p, 0);

    if (p && !q)
        free(p);

    return 0;
}
EOF
*** glibc detected *** double free or corruption (fasttop): 0x0000000000501010
***
Aborted

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2019-10-03 11:58 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-06 22:48 [Bug libc/12547] New: realloc(p, 0) violates C99 msebor at gmail dot com
2011-03-11  1:11 ` [Bug libc/12547] " drepper.fsp at gmail dot com
2011-03-17 19:03 ` jsm28 at gcc dot gnu.org
2011-03-24 17:10 ` eblake at redhat dot com
2011-03-24 17:20 ` eblake at redhat dot com
2011-03-24 17:23 ` jakub at redhat dot com
2011-03-25  0:08 ` bruno at clisp dot org
2011-04-01 22:52 ` eblake at redhat dot com
2011-04-01 23:40 ` drepper.fsp at gmail dot com
2011-04-07 17:06 ` nick at usenix dot org
2014-02-16 17:51 ` jackie.rosen at hushmail dot com
2014-05-28 19:43 ` schwab at sourceware dot org
2014-06-27 13:47 ` fweimer at redhat dot com
2015-02-22 20:49 ` bugdal at aerifal dot cx
2015-02-23 12:19 ` joseph at codesourcery dot com
2015-02-23 18:09 ` bugdal at aerifal dot cx
2015-02-27 18:11 ` bruno at clisp dot org
2015-02-27 19:11 ` bugdal at aerifal dot cx
2015-08-22 20:32 ` [Bug malloc/12547] " jsm28 at gcc dot gnu.org
2019-10-03 11:58 ` bugdal at aerifal dot cx

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).