From owner-freebsd-questions@FreeBSD.ORG Sat Sep 20 22:15:49 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 4D7031065670 for ; Sat, 20 Sep 2008 22:15:49 +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 BB2548FC30 for ; Sat, 20 Sep 2008 22:15:48 +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 m8KMFbIa023597 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Sun, 21 Sep 2008 01:15:42 +0300 Received: from kobe.laptop (kobe.laptop [127.0.0.1]) by kobe.laptop (8.14.3/8.14.3) with ESMTP id m8KMFbgh003010; Sun, 21 Sep 2008 01:15:37 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Received: (from keramida@localhost) by kobe.laptop (8.14.3/8.14.3/Submit) id m8KMFamA003009; Sun, 21 Sep 2008 01:15:36 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) From: Giorgos Keramidas To: unga888@yahoo.com References: <55974.31287.qm@web57001.mail.re3.yahoo.com> Date: Sun, 21 Sep 2008 01:15:36 +0300 In-Reply-To: <55974.31287.qm@web57001.mail.re3.yahoo.com> (Unga's message of "Sat, 20 Sep 2008 07:04:03 -0700 (PDT)") Message-ID: <873ajuv4zb.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: m8KMFbIa023597 X-Hellug-MailScanner: Found to be clean X-Hellug-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=-3.852, 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: freebsd-questions@freebsd.org, Nash Nipples Subject: Re: Segmentation fault when free [SOLVED] 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 22:15:49 -0000 On Sat, 20 Sep 2008 07:04:03 -0700 (PDT), Unga wrote: >On Sat, 9/20/08, Giorgos Keramidas wrote: >>> : free(0xbfbfc9c9) >>> >>> 1. This clearly shows my program is trying to free a memory that >>> has not been allocated. How it could have happened? >> >> Aha. This looks remarkably like an address in the runtime stack. It >> usually happens when you have a function that returns the address of >> a 'local' variable, instead of a newly allocated heap area, i.e.: >> >> char * >> function(void) >> { >> char buffer[100]; >> >> return buf; >> } > > This was indeed the case, worst yet, I was trying to free a part of > the buffer (as per your example above) by mistake which was not > allocated by malloc. > > Thank you all who helped me. Great! You are welcome, of course :)