Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 20 Sep 1998 01:18:00 +1000 (EST)
From:      Simon Coggins <simon@oz.org>
To:        current@FreeBSD.ORG
Subject:   free() isn't threads safe!
Message-ID:  <Pine.BSF.4.02.9809200113170.9082-100000@chaotic.oz.org>

next in thread | raw e-mail | index | archive | help

While trying to get a threads program working I noticed it was locking up
after it returned a free() error avout recursive call.. 

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?
    THREAD_LOCK();
    if (malloc_active++) {
        wrtwarning("recursive call.\n");
        malloc_active--;
        return; <--------- Shouldn't the thread be unlocked before returning?
    }
    ifree(ptr);
    UTRACE(ptr, 0, 0);
    malloc_active--;
    THREAD_UNLOCK();
    return;
}


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;
    }
    ifree(ptr);
    UTRACE(ptr, 0, 0);
    malloc_active--;
    THREAD_UNLOCK();
    return;
}

Be more sensable?



Regards
Simon

---
      +---------------------------------------------------------------+
      |  Email: chaos@ultra.net.au, chaos@oz.org, simon@bofh.com.au   |
      |   http://www.ultra.net.au/~chaos   Simon.Coggins@jcu.edu.au.  |
      |       Chaos on IRC,    IRC Operator for the OzORG Network     |
      +---------------------------------------------------------------+



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.02.9809200113170.9082-100000>