From owner-freebsd-stable Wed Sep 25 14:43:36 2002 Delivered-To: freebsd-stable@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id ED91337B401 for ; Wed, 25 Sep 2002 14:43:34 -0700 (PDT) Received: from alcanet.com.au (mail2.alcanet.com.au [203.62.196.17]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8378743E65 for ; Wed, 25 Sep 2002 14:43:33 -0700 (PDT) (envelope-from peter.jeremy@alcatel.com.au) Received: from sydsmtp01.alcatel.com.au (IDENT:root@localhost.localdomain [127.0.0.1]) by alcanet.com.au (8.12.4/8.12.4/Alcanet1.3) with ESMTP id g8PLhQu9011178; Thu, 26 Sep 2002 07:43:26 +1000 Received: from gsmx07.alcatel.com.au ([139.188.20.247]) by sydsmtp01.alcatel.com.au (Lotus Domino Release 5.0.11) with ESMTP id 2002092607432297:20391 ; Thu, 26 Sep 2002 07:43:22 +1000 Received: from gsmx07.alcatel.com.au (localhost [127.0.0.1]) by gsmx07.alcatel.com.au (8.12.5/8.12.5) with ESMTP id g8PLhM2t033034; Thu, 26 Sep 2002 07:43:22 +1000 (EST) (envelope-from peter.jeremy@alcatel.com.au) Received: (from jeremyp@localhost) by gsmx07.alcatel.com.au (8.12.5/8.12.5/Submit) id g8PLhMBu033033; Thu, 26 Sep 2002 07:43:22 +1000 (EST) (envelope-from peter.jeremy@alcatel.com.au) Date: Thu, 26 Sep 2002 07:43:22 +1000 From: Peter Jeremy To: David Schultz Cc: stable@FreeBSD.ORG Subject: Re: [v]asprintf leaks memory Message-ID: <20020925214322.GL495@gsmx07.alcatel.com.au> Mail-Followup-To: David Schultz , stable@FreeBSD.ORG References: <20020925133219.GA59210@HAL9000.homeunix.com> Mime-Version: 1.0 In-Reply-To: <20020925133219.GA59210@HAL9000.homeunix.com> User-Agent: Mutt/1.4i X-MIMETrack: Itemize by SMTP Server on SYDSMTP01/AlcatelAustralia(Release 5.0.11 |July 24, 2002) at 26/09/2002 07:43:22 AM, Serialize by Router on SYDSMTP01/AlcatelAustralia(Release 5.0.11 |July 24, 2002) at 26/09/2002 07:43:26 AM, Serialize complete at 26/09/2002 07:43:26 AM Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Sender: owner-freebsd-stable@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On 2002-Sep-25 06:32:19 -0700, David Schultz wrote: >2) reallocf(NULL, x) is equivalent to malloc(x), which is the > source of this bug. Maybe it shouldn't do that. The man page specifically states that realloc(NULL, x) is equivalent to malloc(x) and that reallocf() is the same as malloc() except that it frees the argument if the realloc() fails. IMHO, the ability to realloc(NULL, x) simplifies code: Where you have a grow-on-demand buffer, there's no need to special-case the first use. In wrapper functions (eg zrealloc()), there's no need to explicitly check for NULL. Also IMHO, having realloc() and reallocf() behave differently for NULL buffers would cause much confusion. At the very least, it would make converting realloc() to reallocf() significantly more difficult. If reallocf(NULL, x) isn't equivalent to malloc(x), what behaviour should it have? In the case of [v]asprintf(3), propagating the NULL simplifies the code because it propagates a preceeding error state. Other uses for reallocf() may prefer different behaviour. Overall (IMHO): - realloc(NULL, x) == malloc(x) is the cleanest behaviour - reallocf(NULL, x) similar to realloc(NULL, x) meets POLA - Applications that need different semantics should implement them themselves. Peter To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-stable" in the body of the message