From owner-freebsd-bugs@FreeBSD.ORG Sat Feb 14 16:30:17 2004 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B2EFA16A4CE for ; Sat, 14 Feb 2004 16:30:17 -0800 (PST) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id AEB6343D2D for ; Sat, 14 Feb 2004 16:30:17 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) i1F0UHbv038522 for ; Sat, 14 Feb 2004 16:30:17 -0800 (PST) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.10/8.12.10/Submit) id i1F0UHYx038517; Sat, 14 Feb 2004 16:30:17 -0800 (PST) (envelope-from gnats) Resent-Date: Sat, 14 Feb 2004 16:30:17 -0800 (PST) Resent-Message-Id: <200402150030.i1F0UHYx038517@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Stefan Farfeleder Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1F6AB16A4CE; Sat, 14 Feb 2004 16:20:35 -0800 (PST) Received: from laika.ifs.tuwien.ac.at (laika.ifs.tuwien.ac.at [128.131.167.43]) by mx1.FreeBSD.org (Postfix) with ESMTP id D1F2443D1F; Sat, 14 Feb 2004 16:20:34 -0800 (PST) (envelope-from stefan@fafoe.narf.at) Received: from fafoe.narf.at (unknown [212.186.3.235]) by laika.ifs.tuwien.ac.at (Postfix) with ESMTP id 21CC620A1; Sun, 15 Feb 2004 01:22:33 +0100 (CET) Received: from wombat.fafoe.narf.at (wombat.fafoe.narf.at [192.168.1.42]) by fafoe.narf.at (Postfix) with ESMTP id 0F05340EE; Sun, 15 Feb 2004 01:20:27 +0100 (CET) Received: by wombat.fafoe.narf.at (Postfix, from userid 1001) id 0939A32A; Sun, 15 Feb 2004 01:20:26 +0100 (CET) Message-Id: <20040215002026.0939A32A@wombat.fafoe.narf.at> Date: Sun, 15 Feb 2004 01:20:26 +0100 (CET) From: Stefan Farfeleder To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 cc: stefan@fafoe.narf.at cc: marcel@FreeBSD.org Subject: bin/62859: [patch] malloc(0) fails to call malloc_init() X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Stefan Farfeleder List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 Feb 2004 00:30:17 -0000 >Number: 62859 >Category: bin >Synopsis: [patch] malloc(0) fails to call malloc_init() >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sat Feb 14 16:30:17 PST 2004 >Closed-Date: >Last-Modified: >Originator: Stefan Farfeleder >Release: FreeBSD 5.2-CURRENT i386 >Organization: >Environment: System: FreeBSD wombat.fafoe.narf.at 5.2-CURRENT FreeBSD 5.2-CURRENT #13: Thu Feb 5 23:10:05 CET 2004 stefan@wombat.fafoe.narf.at:/usr/home/stefan/freebsd/obj/usr/home/stefan/freebsd/src/sys/WOMBAT i386 >Description: The function malloc_init() parses malloc()'s options from /etc/malloc.conf, MALLOC_OPTIONS and _malloc_options. It's the function imalloc() that calls malloc_init(), and the former one is not called on malloc(0). This isn't a problem per se, but the v/V flag controls the behaviour of malloc(0) and so it never returns a null pointer until malloc() is called with a positived size. >How-To-Repeat: This program demonstrates that the V flag is ignored: #include #include int main(void) { _malloc_options = "V"; printf("malloc(0) = %p\n", malloc(0)); return (0); } >Fix: This moves the malloc_init() calls into malloc() and realloc(). --- malloc.c.diff begins here --- Index: src/lib/libc/stdlib/malloc.c =================================================================== RCS file: /usr/home/ncvs/src/lib/libc/stdlib/malloc.c,v retrieving revision 1.84 diff -I.svn -u -r1.84 malloc.c --- src/lib/libc/stdlib/malloc.c 28 Nov 2003 18:03:22 -0000 1.84 +++ src/lib/libc/stdlib/malloc.c 14 Feb 2004 23:42:47 -0000 @@ -736,9 +736,6 @@ { void *result; - if (!malloc_started) - malloc_init(); - if (suicide) abort(); @@ -1111,6 +1108,9 @@ { void *r; + if (!malloc_started) + malloc_init(); + _MALLOC_LOCK(); malloc_func = " in malloc():"; if (malloc_active++) { @@ -1161,6 +1161,9 @@ { void *r; int err = 0; + + if (!malloc_started) + malloc_init(); _MALLOC_LOCK(); malloc_func = " in realloc():"; --- malloc.c.diff ends here --- >Release-Note: >Audit-Trail: >Unformatted: