From owner-freebsd-current Sat Sep 19 14:05:04 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id OAA25681 for freebsd-current-outgoing; Sat, 19 Sep 1998 14:05:04 -0700 (PDT) (envelope-from owner-freebsd-current@FreeBSD.ORG) Received: from nash.pr.mcs.net (nash.pr.mcs.net [204.95.47.72]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id OAA25659 for ; Sat, 19 Sep 1998 14:04:58 -0700 (PDT) (envelope-from alex@nash.pr.mcs.net) Received: (from alex@localhost) by nash.pr.mcs.net (8.8.8/8.8.7) id QAA02198; Sat, 19 Sep 1998 16:04:12 -0500 (CDT) (envelope-from alex) Message-ID: <19980919160412.G16974@pr.mcs.net> Date: Sat, 19 Sep 1998 16:04:12 -0500 From: Alex Nash To: chaos@ultra.net.au, current@FreeBSD.ORG Subject: Re: free() isn't threads safe! References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.93.2i In-Reply-To: ; from Simon Coggins on Sun, Sep 20, 1998 at 01:18:00AM +1000 X-Operating-System: FreeBSD 3.0-CURRENT i386 Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Sun, Sep 20, 1998 at 01:18:00AM +1000, Simon Coggins wrote: > This is the code from lib/libc/stdlib/malloc.c > > void > free(void *ptr) > { > malloc_func = " in free():"; <- isn't there a slim chance this can be > changed before the thread is locked? Right you are. In fact malloc() and realloc() had the same problem. > THREAD_LOCK(); > if (malloc_active++) { > wrtwarning("recursive call.\n"); > malloc_active--; > return; <--------- Shouldn't the thread be unlocked before returning? Yes. > Wouldn't something like: > > void > free(void *ptr) > { > THREAD_LOCK(); > malloc_func = " in free():"; > if (malloc_active++) { > wrtwarning("recursive call.\n"); > malloc_active--; > THREAD_UNLOCK(); > return; > } [...] > Be more sensable? I committed a slightly different fix to -current (I'll merge this back into -stable later this weekend) using a single exit point from free(). Cue Terry to explain the advantages of single entry/single exit functions... Alex To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message