From owner-freebsd-questions@FreeBSD.ORG Sat Sep 20 09:06:09 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 3F77F106566B for ; Sat, 20 Sep 2008 09:06:09 +0000 (UTC) (envelope-from unga888@yahoo.com) Received: from web57004.mail.re3.yahoo.com (web57004.mail.re3.yahoo.com [66.196.97.108]) by mx1.freebsd.org (Postfix) with SMTP id C18BF8FC14 for ; Sat, 20 Sep 2008 09:06:03 +0000 (UTC) (envelope-from unga888@yahoo.com) Received: (qmail 1991 invoked by uid 60001); 20 Sep 2008 09:06:03 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Mailer:Date:From:Reply-To:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Message-ID; b=Z/qWmf5lg+C5WXFb8Xpa/acpAY/9KM28XbcpkorPKnmgesAq6DV2yA2p0tSxlkCTB3sPXKuwaE/GqaDfQEzbbsEPi60rMttU6+lzvynBM89kpu6r4vfTx4fj7wNDlNloza84I6GUq1R1BOAQc4XPp/k9wtzQfx9OcXFyB4OAq9g=; X-YMail-OSG: 2S_DMWsVM1nc1CYCfdM01rfzyOu_PYtLH9TDf1COvjwlxi20SBSTGqwaWP6V2_SBNDn4L0tksH1jaXjXEHAbkndOkFPNl_YQgMhRvR5yIX94m4Dh199cEeImSqtUvWMhejfGkmtuY8zgh1ySVio2jmMARjlDiuAKYuEmIH9mHkXyEDQrIriJ Received: from [220.255.7.177] by web57004.mail.re3.yahoo.com via HTTP; Sat, 20 Sep 2008 02:06:02 PDT X-Mailer: YahooMailWebService/0.7.218.2 Date: Sat, 20 Sep 2008 02:06:02 -0700 (PDT) From: Unga To: Giorgos Keramidas In-Reply-To: <87bpyj9qi9.fsf@kobe.laptop> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Message-ID: <958402.1645.qm@web57004.mail.re3.yahoo.com> 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 Reply-To: unga888@yahoo.com List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 20 Sep 2008 09:06:09 -0000 --- On Sat, 9/20/08, Giorgos Keramidas wrote: > > 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 problem happens very early stage of my program. Its the very first free() develops a problem. I checked again, up to the this problematic free(), functions return newly allocated strings properly: char *f( ) { char *newstr = NULL; : newstr = (char *) malloc(p - sp + 1); if (newstr == NULL) return NULL; : return newstr; } Can a yet not executed wrong free() elsewhere cause a problem of this nature? Best regards Unga