From owner-freebsd-questions@FreeBSD.ORG Fri Jun 11 19:23:49 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 1F1041065675 for ; Fri, 11 Jun 2010 19:23:49 +0000 (UTC) (envelope-from Vikash.Badal@is.co.za) Received: from morpheus.is.co.za (morpheus.is.co.za [196.35.45.229]) by mx1.freebsd.org (Postfix) with ESMTP id 90A1F8FC16 for ; Fri, 11 Jun 2010 19:23:48 +0000 (UTC) Received: from morpheus.is.co.za (localhost.is.co.za [127.0.0.1]) by morpheus.is.co.za (Postfix) with ESMTP id DEC95F3B1E for ; Fri, 11 Jun 2010 21:23:45 +0200 (SAST) Received: from ZABRYSVISMFW (zajnbisit.mfw.is.co.za [196.26.2.106]) by morpheus.is.co.za (Postfix) with ESMTP id B4CD9F3B17 for ; Fri, 11 Jun 2010 21:23:45 +0200 (SAST) Received: from zabrysvisexhub3.af.didata.local (Not Verified[10.1.8.38]) by ZABRYSVISMFW with MailMarshal (v6, 5, 4, 7535) id ; Fri, 11 Jun 2010 21:23:54 +0200 Received: from ZABRYSVISEXMBX1.af.didata.local ([fe80::914a:a14c:13c1:d279]) by zabrysvisexhub3.af.didata.local ([fe80::9023:67c3:e2b7:a5ba%10]) with mapi; Fri, 11 Jun 2010 21:23:03 +0200 From: Vikash Badal To: "freebsd-questions@freebsd.org" Date: Fri, 11 Jun 2010 21:23:43 +0200 Thread-Topic: threads and malloc/free on freebsd 8.0 Thread-Index: Acr4/nWBtJH08K8LQF2QG0p7qeSiSQQnN2SA Message-ID: <9B425C841283E0418B1825D40CBCFA613D9E3CA643@ZABRYSVISEXMBX1.af.didata.local> Accept-Language: en-US, en-ZA Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US, en-ZA Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Virus-Scanned: ClamAV using ClamSMTP Subject: 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, 11 Jun 2010 19:23:49 -0000 Greetings. I have a thread socket application that seems to be behaving strangely In a worker thread, I have the following. ----------- =20 LogMessage(DEBUG_0, "allocated %ld", malloc_usable_size(inst)); =20 =20 =20 free(inst); =20 =20 =20 LogMessage(DEBUG_0, "after free allocated %ld", malloc_usable_size(i= nst)); =20 free(inst); =20 =20 =20 return 0; ----------- output> allocated 2304 output> after free allocated 2304 from playing around, this should have segfaulted but it didn't: if I try this from a non threaded, non socket code: ------------------ =20 char *z; =20 z =3D (char*)malloc(1000); =20 printf("malloc is %ld\n", malloc_usable_size(z)); =20 free(z); =20 printf("after malloc is %ld\n", malloc_usable_size(z)); ------------------ Output> malloc is 1024 Output> Segmentation fault (core dumped) Can anyone enlighten me ? why did the 2nd free not cause a segmentation f= ault ? If im not clear, please forgive me. Please note: This email and its content are subject to the disclaimer as = displayed at the following link http://www.is.co.za/legal/E-mail+Confiden= tiality+Notice+and+Disclaimer.htm. Should you not have Web access, send a= =20mail to disclaimers@is.co.za and a copy will be emailed to you.