Date: Wed, 28 Jan 2009 17:32:27 +0530 From: Channa <channa.kad@gmail.com> To: Harti Brandt <harti@freebsd.org> Cc: freebsd-current@freebsd.org Subject: Re: Jemalloc SEGV for 1MB chunk Message-ID: <515c64960901280402s529d243fg8b6e0c58dc90b64@mail.gmail.com> In-Reply-To: <20090128124535.M26828@beagle.kn.op.dlr.de> References: <515c64960901280339m17fa9309v2e1bc3f55454ab@mail.gmail.com> <20090128124535.M26828@beagle.kn.op.dlr.de>
next in thread | previous in thread | raw e-mail | index | archive | help
Hi, Thanks for your reply. You mean to say i should modify the test as below: #include <stdio.h> #include <stdlib.h> #include <string.h> 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? Regards, Channa On 28/01/2009, Harti Brandt <hartmut.brandt@dlr.de> wrote: > On Wed, 28 Jan 2009, Channa wrote: > > C>Hi All, > C>I am using jemalloc.c source from FreeBSD-current source. > C>When i allocate 1MB of memory using malloc() and use it as the below > C>test shows > C> > C>#include <stdio.h> > C>#include <stdlib.h> > C>#include <string.h> > C> > C>int main() > C>{ > C> int i; > C> char *buf; > C> size_t size = 1048576 ; > C> > C> buf = malloc(size); > C> for (i = 0; i < 1048576; i++) > C> buf[i] = 'a'; > C> printf("The length of buff is : %d\n",strlen(buf)); > C> free(buf); > C> return 0; > C>} > C> > C>When i try to call strlen(buf) SEGV is recived. > > Would be better to terminate the string with a '\0' so that it is really a > string. > > harti > > C> > C>This behaviour is seen when only for 1MB chunk if i allocate > C>memory lesser than 1MB no issues noticed. > C> > C>Could anyone see similar problem? > C>Is the above test wrong? > C>Or some issue with huge memory allocation in jemalloc? > C> > C>Your response will be very helpful. > C> > C>Thanks & Regards, > C>Channa > C>_______________________________________________ > C>freebsd-current@freebsd.org mailing list > C>http://lists.freebsd.org/mailman/listinfo/freebsd-current > C>To unsubscribe, send any mail to "freebsd-current-unsubscribe@freebsd.org" > C> > C> >
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?515c64960901280402s529d243fg8b6e0c58dc90b64>