From owner-freebsd-current@FreeBSD.ORG Thu Jan 29 12:28:24 2009 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0C6751065674 for ; Thu, 29 Jan 2009 12:28:24 +0000 (UTC) (envelope-from ticso@cicely7.cicely.de) Received: from raven.bwct.de (raven.bwct.de [85.159.14.73]) by mx1.freebsd.org (Postfix) with ESMTP id 66DBF8FC1A for ; Thu, 29 Jan 2009 12:28:23 +0000 (UTC) (envelope-from ticso@cicely7.cicely.de) Received: from cicely5.cicely.de ([10.1.1.7]) by raven.bwct.de (8.13.4/8.13.4) with ESMTP id n0TCHr48067956 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 29 Jan 2009 13:17:54 +0100 (CET) (envelope-from ticso@cicely7.cicely.de) Received: from cicely7.cicely.de (cicely7.cicely.de [10.1.1.9]) by cicely5.cicely.de (8.14.2/8.14.2) with ESMTP id n0TCHpnn098483 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 29 Jan 2009 13:17:51 +0100 (CET) (envelope-from ticso@cicely7.cicely.de) Received: from cicely7.cicely.de (localhost [127.0.0.1]) by cicely7.cicely.de (8.14.2/8.14.2) with ESMTP id n0TCHpsO078059; Thu, 29 Jan 2009 13:17:51 +0100 (CET) (envelope-from ticso@cicely7.cicely.de) Received: (from ticso@localhost) by cicely7.cicely.de (8.14.2/8.14.2/Submit) id n0TCHofi078058; Thu, 29 Jan 2009 13:17:50 +0100 (CET) (envelope-from ticso) Date: Thu, 29 Jan 2009 13:17:50 +0100 From: Bernd Walter To: Channa Message-ID: <20090129121750.GO74490@cicely7.cicely.de> References: <515c64960901280339m17fa9309v2e1bc3f55454ab@mail.gmail.com> <49804597.6040303@gmx.de> <515c64960901280401w1e1d08bfx29adc124bc749c4a@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <515c64960901280401w1e1d08bfx29adc124bc749c4a@mail.gmail.com> X-Operating-System: FreeBSD cicely7.cicely.de 7.0-STABLE i386 User-Agent: Mutt/1.5.11 X-Spam-Status: No, score=-4.3 required=5.0 tests=ALL_TRUSTED=-1.8, AWL=0.053, BAYES_00=-2.599 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on spamd.cicely.de Cc: Christoph Mallon , freebsd-current@freebsd.org Subject: Re: Jemalloc SEGV for 1MB chunk X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: ticso@cicely.de List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Jan 2009 12:28:24 -0000 On Wed, Jan 28, 2009 at 05:31:43PM +0530, Channa wrote: > Hi, > Thanks for your reply. > You mean to say i should modify the test as below: > > #include > #include > #include > > > int main() > { > int i; > char *buf; > size_t size = 1048576 ; > > buf = malloc(size); > for (i = 0; i <= 1048575; i++) > buf[i] = 'a'; > buf[size]='\0'; > printf("The length of buff is : %d\n",strlen(buf)); > free(buf); > return 0; > } > > I NULL terminated the string > buf[size] = '\0' <== The last character is NULL > > But still i get a SEGV at strlen. > > Could you please tell me if my changes above are correct? buf[size - 1]='\0'; It should panic with this line instead of strlen, because you tried writing one byte behind allocation. Originally your code wasn't terminating the string at all so strlen was the first one to access behind allocation. -- B.Walter http://www.bwct.de Modbus/TCP Ethernet I/O Baugruppen, ARM basierte FreeBSD Rechner uvm.