Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 22 May 2010 01:28:11 +0530
From:      Anoop Kumar Narayanan <anoop.kn@gmail.com>
To:        "freebsd-questions@freebsd.org" <freebsd-questions@freebsd.org>
Subject:   Re: threads and malloc/free on freebsd 8.0
Message-ID:  <AANLkTimxAt-VmTgEZwyJp5UXIWbkxpteJXP7mZ_Qwm9q@mail.gmail.com>
In-Reply-To: <20100521191856.GA8866@dan.emsphone.com>
References:  <9B425C841283E0418B1825D40CBCFA613D9E2689CF@ZABRYSVISEXMBX1.af.didata.local> <20100521191856.GA8866@dan.emsphone.com>

next in thread | previous in thread | raw e-mail | index | archive | help
I think glibc uses asynchronous free, as in it doesn't free the memory
immediately. So even though the memory is free'd its still part of the
process's address space but present in the free pool and so it doesn't
crash.

-Anoop

On Sat, May 22, 2010 at 12:48 AM, Dan Nelson <dnelson@allantgroup.com> wrot=
e:
> In the last episode (May 21), Vikash Badal said:
>> Excuse me if this is a stupid questions.
>>
>> I have a thread socket application that seems to be behaving strangely
>>
>> In a worker thread, I have the following.
>>
>> <CODE>-----------
>> =A0 =A0LogMessage(DEBUG_0, "allocated %ld", malloc_usable_size(inst));
>>
>> =A0 =A0free(inst);
>>
>> =A0 =A0LogMessage(DEBUG_0, "after free allocated %ld", malloc_usable_siz=
e(inst));
>>
>> =A0 =A0 return 0;
>> -----------</CODE>
>>
>> output> allocated 2304
>> output> after free allocated 2304
>>
>> from playing around, this should have segfaulted but it didn't
>
> You're invoking undefined behaviour here by calling malloc_usable_size on=
 a
> free'd pointer. =A0The function is free to crash, return useful data, or
> return useless data, at its discretion :)
>
> As long as you only call it on pointers that are still valid you will be
> okay.
>
> --
> =A0 =A0 =A0 =A0Dan Nelson
> =A0 =A0 =A0 =A0dnelson@allantgroup.com
> _______________________________________________
> freebsd-questions@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.o=
rg"
>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?AANLkTimxAt-VmTgEZwyJp5UXIWbkxpteJXP7mZ_Qwm9q>