From owner-freebsd-current@FreeBSD.ORG Wed Jan 28 12:25: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 1C1AF106594B for ; Wed, 28 Jan 2009 12:25:24 +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 E017E8FC22 for ; Wed, 28 Jan 2009 12:25:23 +0000 (UTC) (envelope-from channa.kad@gmail.com) Received: by rv-out-0506.google.com with SMTP id b25so7038735rvf.43 for ; Wed, 28 Jan 2009 04:25:23 -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=NdBz7s2mC9iPEaBsPhQ+LCR0q1UWBpbLwnVHgz72eoo=; b=fQSJQaMamjwN00QSTx0BXWXDOFVquMW1tDxUqccyOg9B1cm3vUIXLlm9Tf9GEHy6aV ovwR74RR2ng8UHHGR9ezBlILbzhp+BVMkNLtTV3UAId02jDhA/PE9yk/uODiX76+946h iXXVMURrW9XDwrbEFUZ+Gjs0ox7lbGO2vl8T4= 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=QLGcAIN/p5aqou2JyjqP7tp+HdtgRB8C/1VnfdM+l2UfpxKldezGLwi6voLPUcx6RY IkoYC/a84XJ2FjwY7tzeu527FAEDKDs6KUZgVtDarkAGEZoY1zjcY5NfI/EVfvZyK5JT metZCbY19sYkfjBKcI2lBQN1tpTFkgGvQyYLM= MIME-Version: 1.0 Received: by 10.140.147.5 with SMTP id u5mr990011rvd.86.1233145523488; Wed, 28 Jan 2009 04:25:23 -0800 (PST) In-Reply-To: References: <515c64960901280339m17fa9309v2e1bc3f55454ab@mail.gmail.com> <49804597.6040303@gmx.de> <515c64960901280401w1e1d08bfx29adc124bc749c4a@mail.gmail.com> Date: Wed, 28 Jan 2009 17:55:23 +0530 Message-ID: <515c64960901280425y642a190ka31409cfc2a2fd8f@mail.gmail.com> From: Channa To: Danny Braniss Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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 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:25:25 -0000 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? Thanks in Advance, Channa On 28/01/2009, Danny Braniss 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? > > > > clear case of off by one. > you are requesting 'size' bytes, indexing starts at 0, all the way to size-1 > which is ALL the bytes you malloc'ed > then you zero the size+1 byte, ah, btw, it's not strlen that is SEGV'ing. > > > danny > > > > Regards, > > Channa > > > > > > On 28/01/2009, Christoph Mallon wrote: > > > Channa schrieb: > > > > > > > > > > Hi All, > > > > I am using jemalloc.c source from FreeBSD-current source. > > > > When i allocate 1MB of memory using malloc() and use it as the below > > > > test shows > > > > > > > > #include > > > > #include > > > > #include > > > > > > > > int main() > > > > { > > > > int i; > > > > char *buf; > > > > size_t size = 1048576 ; > > > > > > > > buf = malloc(size); > > > > for (i = 0; i < 1048576; i++) > > > > buf[i] = 'a'; > > > > printf("The length of buff is : %d\n",strlen(buf)); > > > > free(buf); > > > > return 0; > > > > } > > > > > > > > When i try to call strlen(buf) SEGV is recived. > > > > > > > > This behaviour is seen when only for 1MB chunk if i allocate > > > > memory lesser than 1MB no issues noticed. > > > > > > > > Could anyone see similar problem? > > > > Is the above test wrong? > > > > Or some issue with huge memory allocation in jemalloc? > > > > > > > > Your response will be very helpful. > > > > > > > > Thanks & Regards, > > > > Channa > > > > > > > > > > You did not NUL-terminate ('\0') the string. > > > > > > _______________________________________________ > > 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" > > > > >