From owner-freebsd-current@FreeBSD.ORG Wed Jan 28 12:37:19 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 58996106567A for ; Wed, 28 Jan 2009 12:37:19 +0000 (UTC) (envelope-from channa.kad@gmail.com) Received: from rv-out-0506.google.com (rv-out-0506.google.com [209.85.198.228]) by mx1.freebsd.org (Postfix) with ESMTP id 29A9E8FC0A for ; Wed, 28 Jan 2009 12:37:19 +0000 (UTC) (envelope-from channa.kad@gmail.com) Received: by rv-out-0506.google.com with SMTP id g9so1801157rvb.3 for ; Wed, 28 Jan 2009 04:37:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=snO3NPVxKjENgkQIRCvV505z871rvq1iOnJp8dYZYT8=; b=RBam5HhPJMh588DP2boJcMTNU8mI4BhtcbvnVktZSnc0e9X2dVbALPAwPN6MRfawhc txxF4ynk7OaGH23mjz3JUjD5MDG0y9FnOupqpFkjCNLH9Stj61zInS0efaYgj2vqiG0O wJkP2fHmbT6gCDAAm1GTtj7f0Ht5E/T4nZBsg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=v4XRsYipbATxzhuWQ6FgXINYv657kPWJdQP2plTnqfFniWMxN+CpFFAbmcpF9pjFLZ 5laEPKdjA87k3HwrZpvKguQWHJojGLiC66Shv0SMSYHma3BkaGDuv9YIKeVqr417YYxg lPZsc+HNIuD9eO3mQby6qxVTsMBIL1/OdC2yk= MIME-Version: 1.0 Received: by 10.141.106.14 with SMTP id i14mr1733219rvm.27.1233146238860; Wed, 28 Jan 2009 04:37:18 -0800 (PST) In-Reply-To: <49804FCE.7090405@gmx.de> References: <515c64960901280339m17fa9309v2e1bc3f55454ab@mail.gmail.com> <49804597.6040303@gmx.de> <515c64960901280401w1e1d08bfx29adc124bc749c4a@mail.gmail.com> <515c64960901280425y642a190ka31409cfc2a2fd8f@mail.gmail.com> <49804FCE.7090405@gmx.de> Date: Wed, 28 Jan 2009 18:07:18 +0530 Message-ID: <515c64960901280437hd4f7b2dx36a1774afe2f5646@mail.gmail.com> From: Channa To: Christoph Mallon Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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:37:19 -0000 Hi, Thanks for the reply. Does the same behaviour seen on FreeBSD environment? I am using FreeBSD libraries to test the test code. So according to you its better to NULL terminate in the test code to avoid this undefined behaviour? Thanks , 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 SEGV is > seen. > > > > But if i change the request size to a value less than 1MB for eg: 4096 > Bytes, > > > > As in the below test code: > > > > #include > > #include > > #include > > > > int main() > > { > > int i; > > char *buf; > > size_t size = 4096 ; > > > > buf = malloc(size); > > for (i = 0; i < size; i++) > > buf[i] = '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 from > memory. For a large allocation like 1MB you get page aligned memory and the > page after the allocation is very likely not mapped, so you get a segfault > when you try to access it. > This really does not belong on freebsd-current@. >