From owner-svn-src-all@FreeBSD.ORG Mon Aug 2 09:13:10 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 13CF51065674; Mon, 2 Aug 2010 09:13:10 +0000 (UTC) (envelope-from jh@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 01B108FC1B; Mon, 2 Aug 2010 09:13:10 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o729D9CC075210; Mon, 2 Aug 2010 09:13:09 GMT (envelope-from jh@svn.freebsd.org) Received: (from jh@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o729D9Ob075208; Mon, 2 Aug 2010 09:13:09 GMT (envelope-from jh@svn.freebsd.org) Message-Id: <201008020913.o729D9Ob075208@svn.freebsd.org> From: Jaakko Heinonen Date: Mon, 2 Aug 2010 09:13:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r210745 - stable/8/lib/libc/stdlib X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 Aug 2010 09:13:10 -0000 Author: jh Date: Mon Aug 2 09:13:09 2010 New Revision: 210745 URL: http://svn.freebsd.org/changeset/base/210745 Log: MFC r204636: In reallocf(3), free the memory only when size != 0. Otherwise, when the System V compatibility option (malloc "V" flag) is in effect a zero sized reallocf() could cause a double free. PR: bin/141753 Modified: stable/8/lib/libc/stdlib/reallocf.c Directory Properties: stable/8/lib/libc/ (props changed) stable/8/lib/libc/stdtime/ (props changed) stable/8/lib/libc/sys/ (props changed) Modified: stable/8/lib/libc/stdlib/reallocf.c ============================================================================== --- stable/8/lib/libc/stdlib/reallocf.c Mon Aug 2 09:03:31 2010 (r210744) +++ stable/8/lib/libc/stdlib/reallocf.c Mon Aug 2 09:13:09 2010 (r210745) @@ -35,7 +35,14 @@ reallocf(void *ptr, size_t size) void *nptr; nptr = realloc(ptr, size); - if (!nptr && ptr) + + /* + * When the System V compatibility option (malloc "V" flag) is + * in effect, realloc(ptr, 0) frees the memory and returns NULL. + * So, to avoid double free, call free() only when size != 0. + * realloc(ptr, 0) can't fail when ptr != NULL. + */ + if (!nptr && ptr && size != 0) free(ptr); return (nptr); }