From owner-freebsd-questions@FreeBSD.ORG Sun Sep 21 14:17:47 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 31351106564A for ; Sun, 21 Sep 2008 14:17:46 +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 3D4708FC0C for ; Sun, 21 Sep 2008 14:17:45 +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 m8LEHT5S010465 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Sun, 21 Sep 2008 17:17:35 +0300 Received: from kobe.laptop (kobe.laptop [127.0.0.1]) by kobe.laptop (8.14.3/8.14.3) with ESMTP id m8LEHT5u093982; Sun, 21 Sep 2008 17:17:29 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Received: (from keramida@localhost) by kobe.laptop (8.14.3/8.14.3/Submit) id m8LEHS3W093981; Sun, 21 Sep 2008 17:17:28 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) From: Giorgos Keramidas To: trashy_bumper@yahoo.com References: <266527.92897.qm@web110502.mail.gq1.yahoo.com> Date: Sun, 21 Sep 2008 17:17:27 +0300 In-Reply-To: <266527.92897.qm@web110502.mail.gq1.yahoo.com> (Nash Nipples's message of "Sun, 21 Sep 2008 05:57:06 -0700 (PDT)") Message-ID: <87vdwppoqw.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: m8LEHT5S010465 X-Hellug-MailScanner: Found to be clean X-Hellug-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=-3.853, 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 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: Sun, 21 Sep 2008 14:17:47 -0000 On Sun, 21 Sep 2008 05:57:06 -0700 (PDT), Nash Nipples wrote: > thanks for making it even more clear to me. > actually what i meant was this: > > void function(void){ > char *p; > p = malloc(1); > } > int main(void){ > while (1){ > function(); > /* in the end of this function function() > * the memory is still allocated > * even when the only pointer who knows its address > * does not longer exist > * which is why we have to free() the memory > * during the application runtime > * to avoid it from growing to ridiculous size > */ > } > } This won't throw SEGV in free() because, well, it never calls free(), but it leaks memory like mad :) > but even if you kill -SEGV `pgrep this` (Segmentation fault (core > dumped) the memory is getting freed anyway (presumably by the glorious > kernel). which you can see dynamicly by typing top in the console. Yes. When a process terminates, the kernel dismantles and releases all its 'mapped memory areas', including the heap where malloc()'ed memory comes from.