From owner-freebsd-bugs@FreeBSD.ORG Fri Dec 18 17:20:02 2009 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 57DE5106566C for ; Fri, 18 Dec 2009 17:20:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 2E9E98FC17 for ; Fri, 18 Dec 2009 17:20:02 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id nBIHK2Fn032211 for ; Fri, 18 Dec 2009 17:20:02 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id nBIHK2vg032210; Fri, 18 Dec 2009 17:20:02 GMT (envelope-from gnats) Date: Fri, 18 Dec 2009 17:20:02 GMT Message-Id: <200912181720.nBIHK2vg032210@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Dan Lukes Cc: Subject: Re: bin/141753: double-free in reallocf() X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Dan Lukes List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Dec 2009 17:20:02 -0000 The following reply was made to PR bin/141753; it has been noted by GNATS. From: Dan Lukes To: bug-followup@FreeBSD.org Cc: Subject: Re: bin/141753: double-free in reallocf() Date: Fri, 18 Dec 2009 18:12:00 +0100 I missed simple and obvious fix! Replace > if (!nptr && ptr) > free(ptr); with > if (!nptr && ptr && size > 0) > free(ptr); Because - When size>0 the previous behavior is maintained. When size==0 and V option not set, then nptr!=NULL (realloc(,0) never fail) so the ptr is not free - correct behavior. When size==0 and V option IS set then we know the ptr is freed by realloc and it's not freed again here - correct behavior. Dan