From owner-freebsd-questions@FreeBSD.ORG Fri Sep 19 16:17:19 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 0251C1065673 for ; Fri, 19 Sep 2008 16:17:19 +0000 (UTC) (envelope-from unga888@yahoo.com) Received: from web57007.mail.re3.yahoo.com (web57007.mail.re3.yahoo.com [66.196.97.111]) by mx1.freebsd.org (Postfix) with SMTP id 91ABB8FC19 for ; Fri, 19 Sep 2008 16:17:18 +0000 (UTC) (envelope-from unga888@yahoo.com) Received: (qmail 54209 invoked by uid 60001); 19 Sep 2008 16:17:18 -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:MIME-Version:Content-Type:Message-ID; b=vq+YVChWvoTG6aer9XdDCMKKo3ueFu1Mf+Ci0xElcZ2h+D9uj5QvOMtNZTO82FCGTGIaaD4UIG9YWTjWuKSso6LJ6xAbtaR8Y51lwBrqLghSpCM8uVYzntlDH6qcT8iLciarFW42X1T/LvNBvZZyalSHxALRekZ49nPzFbDHrvQ=; X-YMail-OSG: iO4b5BkVM1m0uevWUUK7gbA41qOy3D36v0tXFO8KFthx8yQYZv4CLmNvQMtNAjFA0pKnZcr32SG46tqyE_u9W41S5TP3ERu4cD7FlG.HkV24PrMB_xHel30R2ZMazEOdbKj71A-- Received: from [220.255.7.169] by web57007.mail.re3.yahoo.com via HTTP; Fri, 19 Sep 2008 09:17:17 PDT X-Mailer: YahooMailWebService/0.7.218.2 Date: Fri, 19 Sep 2008 09:17:17 -0700 (PDT) From: Unga To: freebsd-questions@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Message-ID: <37804.54110.qm@web57007.mail.re3.yahoo.com> Subject: 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: Fri, 19 Sep 2008 16:17:19 -0000 Hi all I'm running FreeBSD 7 on i386. I have a C program compiled with gcc 4.2.1 20070719. Logically my program is: char *a; char *b; char *c; while (cond) { a = f1(); /* malloc() and send a string */ b = f2(); /* malloc() and send a string */ c = (char *) malloc(strlen(a) + strlen(b) + 1); c[0] = '\0'; strcat(c, a); strcat(c, b); free(a); free(b); } When it executes free(b), my program exits with Segmentation fault: 11. The free(a) executes well. The problem is with free(b). Even swap free(b) first and free(a) next, it still crashes at free(b). If I comment out free() lines, further down the program, first few characters of one string get dropped when executes a completely unrelated line. How could I bit more narrow down the problem? Many thanks in advance. Kind regards Unga