From owner-freebsd-questions@FreeBSD.ORG Sat Sep 20 06:23:29 2008 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 EADFA1065671 for ; Sat, 20 Sep 2008 06:23:29 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from igloo.linux.gr (igloo.linux.gr [62.1.205.36]) by mx1.freebsd.org (Postfix) with ESMTP id 4C4878FC12 for ; Sat, 20 Sep 2008 06:23:23 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from kobe.laptop (adsl83-215.kln.forthnet.gr [77.49.50.215]) (authenticated bits=128) by igloo.linux.gr (8.14.3/8.14.3/Debian-5) with ESMTP id m8K6NEb1021656 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Sat, 20 Sep 2008 09:23:20 +0300 Received: from kobe.laptop (kobe.laptop [127.0.0.1]) by kobe.laptop (8.14.3/8.14.3) with ESMTP id m8K6NEUC015260; Sat, 20 Sep 2008 09:23:14 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Received: (from keramida@localhost) by kobe.laptop (8.14.3/8.14.3/Submit) id m8K6NCkj015259; Sat, 20 Sep 2008 09:23:12 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) From: Giorgos Keramidas To: unga888@yahoo.com References: <614097.81584.qm@web57007.mail.re3.yahoo.com> Date: Sat, 20 Sep 2008 09:23:12 +0300 In-Reply-To: <614097.81584.qm@web57007.mail.re3.yahoo.com> (Unga's message of "Fri, 19 Sep 2008 20:03:03 -0700 (PDT)") Message-ID: <874p4bgwtr.fsf@kobe.laptop> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-MailScanner-ID: m8K6NEb1021656 X-Hellug-MailScanner: Found to be clean X-Hellug-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=-3.851, required 5, autolearn=not spam, ALL_TRUSTED -1.80, AWL 0.55, BAYES_00 -2.60) X-Hellug-MailScanner-From: keramida@ceid.upatras.gr X-Spam-Status: No Cc: trashy_bumper@yahoo.com, freebsd-questions@freebsd.org Subject: Re: Segmentation fault when free 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: Sat, 20 Sep 2008 06:23:30 -0000 On Fri, 19 Sep 2008 20:03:03 -0700 (PDT), Unga wrote: > Hi thank you very much for your reply and the test case. > > That is, in a trivial case like this, free() works well. Hopefully > free() works well in all cases too. > > But my main program is 1900 lines, f1() and f2() are in a 2200 lines > second file. The f1() and f2() calls some functions from a 500 lines > third file. The main program call another function, f3(), from 2nd > file, pass pointers to two functions f4(), f5() of main program. The > while loop iterate more than one million times. Its quite a complex > situation. You are probably calling free() multiple times for the same buffer. Try tracing the malloc and free calls, using the information from this message: http://lists.freebsd.org/pipermail/freebsd-questions/2008-July/179480.html > There must be an error somewhere else. I noted free() causes lot of > troubles. It is easy to write complex programs if you just let to leak > memory. But in my case, since the program iterate millions of times, > if I let to leak, I'm sure it will run out of RAM. Leaking memory is *never* a good choice. Especially if you are writing library code that others are supposed to use, or code that is supposed to run millions of times. While it's understandable as a 'quick hack' when you are first writing a program, I've seen far too many 'quick hacks' that lived years and years after the original 'experimental' period passed. Hence the knee-jerk reaction when I see leaks being used as a 'temporary' solution :)