NetBSD Problem Report #1806

From gnats  Sun Dec  3 05:02:50 1995
Received: from icicle by pain.lcs.mit.edu (8.6.12/8.6.9) with ESMTP id EAA29821 for <gnats-bugs@gnats.netbsd.org>; Sun, 3 Dec 1995 04:48:47 -0500
Message-Id: <199512030947.DAA19334@taniemarie.solon.com>
Date: Sun, 3 Dec 1995 03:47:38 -0600
From: Peter Seebach <seebs@taniemarie.solon.com>
Reply-To: seebs@taniemarie.solon.com
To: gnats-bugs@gnats.netbsd.org
Subject: realloc() does not appear to free correctly.
X-Send-Pr-Version: 3.95

>Number:         1806
>Category:       standards
>Synopsis:       realloc(ptr, 0) does not appear to behave correctly
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    gnats-admin
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Dec 03 05:05:00 +0000 1995
>Closed-Date:    Tue Jan 16 21:47:31 +0000 1996
>Last-Modified:  Wed Jan 17 02:48:05 +0000 1996
>Originator:     Peter Seebach
>Release:        November 20 or so
>Organization:
Usenet Fact Police (Undercover)
>Environment:
System: NetBSD taniemarie 1.1 NetBSD 1.1 (SEEBS) #3: Tue Nov 28 18:59:30 CST 1995 seebs@taniemarie:/usr/src/sys/arch/amiga/compile/SEEBS amiga


>Description:
	realloc(ptr, 0) is documented as freeing the given pointer.  It
	does not appear to do so correctly; in any event, repeated
	realloc'ing produces a memory leak.  The code shows no signs of
	checking to see if the desired space is 0.

	Arguably, it should also return NULL for such arguments; after all,
	it returns NULL, or a pointer to the allocated space.  Since
	no space is allocated, there is no allocated space to return a
	pointer to.  The only pointer available which points to no object
	is the null pointer.  :)

	This is a standards bug, because ANSI asserts that realloc(ptr, 0)
	will simply free ptr, and also a practical bug; it is a memory
	leak, if the user (correctly) chooses to ignore the return of
	realloc, which can be a "valid" pointer to 0 bytes of memory.
	(Which is also what you get from malloc(0).  Which is legitimate.)

>How-To-Repeat:
	Allocate space.  realloc() it to 0 bytes.  Repeat.  Watch your
	process size.
>Fix:

	Presumably, realloc(ptr, 0) should just call free(ptr) and return
	a NULL, just as realloc(NULL, size) just acts like a malloc.
>Release-Note:
>Audit-Trail:

State-Changed-From-To: open->closed
State-Changed-By: jtc
State-Changed-When: Tue Jan 16 21:47:31 1996
State-Changed-Why:
Applied fix.

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.