From owner-freebsd-questions@FreeBSD.ORG Fri May 21 19:58:12 2010 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A5D3D1065702 for ; Fri, 21 May 2010 19:58:12 +0000 (UTC) (envelope-from anoop.kn@gmail.com) Received: from mail-pz0-f175.google.com (mail-pz0-f175.google.com [209.85.222.175]) by mx1.freebsd.org (Postfix) with ESMTP id 796498FC14 for ; Fri, 21 May 2010 19:58:12 +0000 (UTC) Received: by pzk5 with SMTP id 5so706221pzk.14 for ; Fri, 21 May 2010 12:58:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=jDhgbp/NQf4YHD+3Y2cOQt1cdoy30skyub9IfwwX/0c=; b=vY+UpkvXGZ5/EX5W6Qi/EhuzvZDEHHq2/mFG+n2h0qzRPKGw42SJm7jmQArErx73mZ qm1X9MnSebf15EY9KKqpKg4piafyLp8udh3yNcqvDU2vUgD3cuNcobevM5+Q2WjLNVyM LmMt7EinqJ9lwuDCrP3rXeAmzEFW/4TL4rGH8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=yATeNE8wpGTc1o3iwb0NoMHbynd7iau76ize/IfVaKrIamSFlnqiJc8NtuDfHuTE5N vDBvwExlwvOoP6Uht4xIs5zYaPfGqyrTfF5sLBJzrcJeLzGhx7YlWvugLuWZPoqiMiuS fW4qBxJfD5W7SUgG4YNiYnym76C92b87Fs1yI= MIME-Version: 1.0 Received: by 10.143.154.27 with SMTP id g27mr1308825wfo.333.1274471891888; Fri, 21 May 2010 12:58:11 -0700 (PDT) Received: by 10.142.170.16 with HTTP; Fri, 21 May 2010 12:58:11 -0700 (PDT) In-Reply-To: <20100521191856.GA8866@dan.emsphone.com> References: <9B425C841283E0418B1825D40CBCFA613D9E2689CF@ZABRYSVISEXMBX1.af.didata.local> <20100521191856.GA8866@dan.emsphone.com> Date: Sat, 22 May 2010 01:28:11 +0530 Message-ID: From: Anoop Kumar Narayanan To: "freebsd-questions@freebsd.org" Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: threads and malloc/free on freebsd 8.0 X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 May 2010 19:58:12 -0000 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 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. >> >> ----------- >> =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; >> ----------- >> >> 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" >