From owner-freebsd-questions@FreeBSD.ORG Fri Jun 11 20:45:21 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 1D086106567E for ; Fri, 11 Jun 2010 20:45:21 +0000 (UTC) (envelope-from dan@dan.emsphone.com) Received: from email1.allantgroup.com (email1.emsphone.com [199.67.51.115]) by mx1.freebsd.org (Postfix) with ESMTP id B930A8FC0A for ; Fri, 11 Jun 2010 20:45:20 +0000 (UTC) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by email1.allantgroup.com (8.14.0/8.14.0) with ESMTP id o5BKjIMV055187 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 11 Jun 2010 15:45:18 -0500 (CDT) (envelope-from dan@dan.emsphone.com) Received: from dan.emsphone.com (smmsp@localhost [127.0.0.1]) by dan.emsphone.com (8.14.4/8.14.4) with ESMTP id o5BKjHGp046342 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 11 Jun 2010 15:45:18 -0500 (CDT) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.14.4/8.14.3/Submit) id o5BKjHA7046341; Fri, 11 Jun 2010 15:45:17 -0500 (CDT) (envelope-from dan) Date: Fri, 11 Jun 2010 15:45:17 -0500 From: Dan Nelson To: Vikash Badal Message-ID: <20100611204517.GC36450@dan.emsphone.com> References: <9B425C841283E0418B1825D40CBCFA613D9E3CA643@ZABRYSVISEXMBX1.af.didata.local> <20100611195628.GB36450@dan.emsphone.com> <9B425C841283E0418B1825D40CBCFA613D9E3CA644@ZABRYSVISEXMBX1.af.didata.local> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9B425C841283E0418B1825D40CBCFA613D9E3CA644@ZABRYSVISEXMBX1.af.didata.local> X-OS: FreeBSD 8.1-PRERELEASE User-Agent: Mutt/1.5.20 (2009-06-14) X-Virus-Scanned: clamav-milter 0.96 at email1.allantgroup.com X-Virus-Status: Clean X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.0.2 (email1.allantgroup.com [199.67.51.78]); Fri, 11 Jun 2010 15:45:18 -0500 (CDT) X-Scanned-By: MIMEDefang 2.45 Cc: "freebsd-questions@freebsd.org" 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, 11 Jun 2010 20:45:21 -0000 In the last episode (Jun 11), Vikash Badal said: > > -----Original Message----- > > From: owner-freebsd-questions@freebsd.org [mailto:owner-freebsd- > > > The fix is to remove your second call to malloc_usable_size(z)). Then > > neither version will crash. Also, a useful habit to start is to > > explicitly zero the pointer you just free'd, to prevent it from being > > used accidentally later. > > Made this change: > > ----------- > LogMessage(DEBUG_0, "allocated %ld", malloc_usable_size(inst)); > > free(inst); > free(inst); > > return 0; > ----------- > > Still no seg fault. > > The reason im am doing this is that from top I can see the memory grow as > I connect to this app. When I disconnect, the memory used ( as displayed > from top ) does not decrease. For performance reasons, the malloc library may not immediately release free memory back to the OS. Also, depending on the position of the memory block being freed, it may not be releasable back to the OS (if malloc used sbrk for allocations, it can only free memory at the far end of the address space, for example). Setting the environment variable MALLOC_OPTIONS to "dM10f" might help (disable use of sbrk(), enable use of mmap(), don't cache any free pages), but you still may not see any change according to top. -- Dan Nelson dnelson@allantgroup.com