Date: Fri, 11 Jun 2010 21:23:43 +0200 From: Vikash Badal <Vikash.Badal@is.co.za> To: "freebsd-questions@freebsd.org" <freebsd-questions@freebsd.org> Subject: threads and malloc/free on freebsd 8.0 Message-ID: <9B425C841283E0418B1825D40CBCFA613D9E3CA643@ZABRYSVISEXMBX1.af.didata.local>
next in thread | raw e-mail | index | archive | help
Greetings. I have a thread socket application that seems to be behaving strangely In a worker thread, I have the following. <CODE>----------- =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; -----------</CODE> 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: <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)); ------------------</CODE> 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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?9B425C841283E0418B1825D40CBCFA613D9E3CA643>