From owner-freebsd-hackers Thu Aug 20 18:02:20 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id SAA02308 for freebsd-hackers-outgoing; Thu, 20 Aug 1998 18:02:20 -0700 (PDT) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from awfulhak.org (awfulhak.force9.co.uk [195.166.136.63]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id SAA02299 for ; Thu, 20 Aug 1998 18:02:17 -0700 (PDT) (envelope-from brian@Awfulhak.org) Received: from gate.lan.awfulhak.org (brian@localhost [127.0.0.1]) by awfulhak.org (8.8.8/8.8.8) with ESMTP id BAA13468; Fri, 21 Aug 1998 01:59:23 +0100 (BST) (envelope-from brian@gate.lan.awfulhak.org) Message-Id: <199808210059.BAA13468@awfulhak.org> X-Mailer: exmh version 2.0.2 2/24/98 To: Warner Losh cc: "Jordan K. Hubbard" , dag-erli@ifi.uio.no (Dag-Erling Coidan =?iso-8859-1?Q?Sm=F8rgrav?= ), hackers@FreeBSD.ORG Subject: Re: Realloc fix for review In-reply-to: Your message of "Thu, 20 Aug 1998 13:09:38 MDT." <199808201909.NAA21884@harmony.village.org> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Date: Fri, 21 Aug 1998 01:59:23 +0100 From: Brian Somers Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by hub.freebsd.org id SAA02304 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG [.....] > No, this only replaces those places where the old pointer was > destroyed rather than a s/realloc/frealloc/g. I was careful to only > change those places where I knew that matched the pattern > a = realloc(a,size); > and didn't change those where they had: > b = realloc(a,size); > Since in the former case you've lost any reference to the old memory, > the right thing to do is to free it up. Since I couldn't change > realloc to have those semantics, I created frealloc which is easier to > use than realloc() in the cases where you want the old memory freed > when it can't allocate new memory. It's still wrong: char *a, *b, *c; ..... a = b; b = realloc(b, 10); if (b == NULL) b = a; ..... or b = NULL; ..... b = realloc(b, 10); etc. Blind replacements are a bad idea. > Warner -- Brian , , Don't _EVER_ lose your sense of humour.... To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message