From owner-freebsd-current@FreeBSD.ORG Wed Jan 28 12:53:54 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 71753106564A for ; Wed, 28 Jan 2009 12:53:54 +0000 (UTC) (envelope-from sos@freebsd.org) Received: from deepcore.dk (adsl.deepcore.dk [87.63.29.106]) by mx1.freebsd.org (Postfix) with ESMTP id D18CF8FC1D for ; Wed, 28 Jan 2009 12:53:53 +0000 (UTC) (envelope-from sos@freebsd.org) Received: from [172.18.2.117] (axiell-gw1.novi.dk [77.243.61.137]) by deepcore.dk (8.14.3/8.14.2) with ESMTP id n0SCrpG4023816; Wed, 28 Jan 2009 13:53:51 +0100 (CET) (envelope-from sos@freebsd.org) Message-Id: From: =?ISO-8859-1?Q?S=F8ren_Schmidt?= To: Channa In-Reply-To: <515c64960901280445l1ab33256sae2e69df30efe502@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed; delsp=yes Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Apple Message framework v930.3) Date: Wed, 28 Jan 2009 13:53:50 +0100 References: <515c64960901280339m17fa9309v2e1bc3f55454ab@mail.gmail.com> <49804597.6040303@gmx.de> <515c64960901280401w1e1d08bfx29adc124bc749c4a@mail.gmail.com> <515c64960901280425y642a190ka31409cfc2a2fd8f@mail.gmail.com> <49804FCE.7090405@gmx.de> <515c64960901280445l1ab33256sae2e69df30efe502@mail.gmail.com> X-Mailer: Apple Mail (2.930.3) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.0 (deepcore.dk [87.63.29.106]); Wed, 28 Jan 2009 13:53:52 +0100 (CET) Cc: 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 List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 Jan 2009 12:53:54 -0000 On 28Jan, 2009, at 13:45 , Channa wrote: > Hi, > "This really does not belong on freebsd-current@." by this you mean to > say in FreeBSD current this problem is not seen. > > Are you referring to FreeBSD current jemalloc version which is =20 > "1.183". > Since i am using the same Version of jemalloc to test the code. > > Could you please elaborate more if my understanding on your statment =20= > is correct? You are using strlen() on a string that is not NULL terminated. That =20 is a violation of how strlen() works, and the result is undefined. =20 That means anything can happen including killing you dog, eating your =20= first born child etc etc. To be brutally honest with you, this is one of the most important =20 things you (should) learn when using strings in 'C', that is why it =20 doesn't belong here on the list. -S=F8ren > > > Thanks in Advance, > Channa > > > On 28/01/2009, Christoph Mallon wrote: >> Channa schrieb: >> >>> Hi, >>> Thanks for the reply. >>> >>> I understand , after terminating the string with NULL character no =20= >>> SEGV is >> seen. >>> >>> But if i change the request size to a value less than 1MB for eg: =20= >>> 4096 >> Bytes, >>> >>> As in the below test code: >>> >>> #include >>> #include >>> #include >>> >>> int main() >>> { >>> int i; >>> char *buf; >>> size_t size =3D 4096 ; >>> >>> buf =3D malloc(size); >>> for (i =3D 0; i < size; i++) >>> buf[i] =3D 'a'; >>> printf("The length of buff is : %d\n",strlen(buf)); >>> free(buf); >>> return 0; >>> } >>> >>> I dont see any issues, without terminating the string with NULL >>> character the test code works fine. The issue is seen only for size >>> 1MB exactly. >>> >>> Can anyone explain this behaviour? >>> >> >> Undefined behaviour and (bad) luck. You are reading random garbage =20= >> from >> memory. For a large allocation like 1MB you get page aligned memory =20= >> and the >> page after the allocation is very likely not mapped, so you get a =20 >> segfault >> when you try to access it. >> This really does not belong on freebsd-current@. >> > _______________________________________________ > freebsd-current@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-current > To unsubscribe, send any mail to = "freebsd-current-unsubscribe@freebsd.org=20 > " > -S=F8ren