NetBSD Problem Report #17163

Received: (qmail 10161 invoked by uid 605); 4 Jun 2002 09:47:38 -0000
Message-Id: <>
Date: Tue,  4 Jun 2002 18:46:59 +0900 (JST)
Subject: libedit leaks memory
X-Send-Pr-Version: 3.95

>Number:         17163
>Category:       lib
>Synopsis:       libedit leaks memory
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jun 04 09:48:01 +0000 2002
>Last-Modified:  Sat Oct 26 17:53:00 +0000 2002
>Originator:     Jun-ichiro itojun Hagino
>Release:        NetBSD 1.6A
System: NetBSD 1.6A NetBSD 1.6A (STARFRUIT) #29: Mon Jun 3 11:35:45 JST 2002 i386
Architecture: i386
Machine: i386
	libedit uses expressions like this:
		p = realloc(p, size);
	it will leak memory on failure.
	the correct construct is;
		q = realloc(p, size);
		if (!q) {
			return FAIL;
		p = q;
	code inspection

From: David Laight <>
Subject: lib/17163
Date: Sat, 26 Oct 2002 18:53:26 +0100

 This is all a huge bag of worms.

 I started trying to fix this (while fixing other broken bits
 of libedit) but it is all too hard (and tedious).
 Large chunks of the libedit code behave badly if any
 of the malloc() calls fails.
 They typically either core dump or leak (more) memory.
 OTOH it isn't obvious what to do in many cases, the structure
 doesn't allow errors to be returned - and in any case if
 malloc is failing getting them to the user starts becoming hard!


 David Laight:

NetBSD Home
NetBSD PR Database Search

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