Date: Fri, 21 May 2010 14:18:56 -0500 From: Dan Nelson <dnelson@allantgroup.com> To: Vikash Badal <Vikash.Badal@is.co.za> Cc: "freebsd-questions@freebsd.org" <freebsd-questions@freebsd.org> Subject: Re: threads and malloc/free on freebsd 8.0 Message-ID: <20100521191856.GA8866@dan.emsphone.com> In-Reply-To: <9B425C841283E0418B1825D40CBCFA613D9E2689CF@ZABRYSVISEXMBX1.af.didata.local> References: <9B425C841283E0418B1825D40CBCFA613D9E2689CF@ZABRYSVISEXMBX1.af.didata.local>
next in thread | previous in thread | raw e-mail | index | archive | help
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>----------- > LogMessage(DEBUG_0, "allocated %ld", malloc_usable_size(inst)); > > free(inst); > > LogMessage(DEBUG_0, "after free allocated %ld", malloc_usable_size(inst)); > > 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. The 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. -- Dan Nelson dnelson@allantgroup.com
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100521191856.GA8866>