From owner-freebsd-questions@FreeBSD.ORG Mon Sep 22 01:43:03 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 CBB8C106564A for ; Mon, 22 Sep 2008 01:43:03 +0000 (UTC) (envelope-from fbsd06+2A=5d787fa8@mlists.homeunix.com) Received: from fallback-in1.mxes.net (fallback-out1.mxes.net [216.86.168.190]) by mx1.freebsd.org (Postfix) with ESMTP id 9B6F48FC12 for ; Mon, 22 Sep 2008 01:43:03 +0000 (UTC) (envelope-from fbsd06+2A=5d787fa8@mlists.homeunix.com) Received: from mxout-03.mxes.net (mxout-03.mxes.net [216.86.168.178]) by fallback-in1.mxes.net (Postfix) with ESMTP id 2BC1E163F5D for ; Sun, 21 Sep 2008 21:32:04 -0400 (EDT) Received: from gumby.homeunix.com. (unknown [87.81.140.128]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.mxes.net (Postfix) with ESMTP id 58BCA23E49E for ; Sun, 21 Sep 2008 21:32:02 -0400 (EDT) Date: Mon, 22 Sep 2008 02:31:57 +0100 From: RW To: freebsd-questions@freebsd.org Message-ID: <20080922023157.6668b46f@gumby.homeunix.com.> In-Reply-To: <266527.92897.qm@web110502.mail.gq1.yahoo.com> References: <200809210206.52409.fbsd.questions@rachie.is-a-geek.net> <266527.92897.qm@web110502.mail.gq1.yahoo.com> X-Mailer: Claws Mail 3.5.0 (GTK+ 2.12.11; i386-portbld-freebsd7.0) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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: Mon, 22 Sep 2008 01:43:03 -0000 On Sun, 21 Sep 2008 05:57:06 -0700 (PDT) Nash Nipples wrote: > 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. The idea that malloc() allocates memory is really a C language abstraction. What it actually does is allocate a region in the process's virtual address space. The mapping of physical memory to virtual address space is handled at a lower-level and doesn't rely on malloc() or free(). > in other words segmentation fault when free() is not a scary thing > here. it is a matter of style and the way to find own errors. or > maybe reading warnings if you compile with the flags -ansi -pedantic I'm not sure what you are saying here, but the handling of dynamic memory in C is something that needs to be well thought-out in advance. Bugs is this area can be very difficult and time-consuming to track-down. > oh and by the way: > > > char * > > function(void) > > { > > char buffer[100]; > > > > return buffer; > > } > > that is an easier approach because you get warned on passing an > address to a local variable This was an example of how to generate a failure, it's not an approach.