Jemalloc SEGV for 1MB chunk

Channa channa.kad at gmail.com
Wed Jan 28 04:45:26 PST 2009


Hi,
"This really does not belong on freebsd-current at ." by this you mean to
say in FreeBSD current this problem is not seen.

Are you referring to FreeBSD current jemalloc version which is "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 is correct?

Thanks in Advance,
Channa


On 28/01/2009, Christoph Mallon <christoph.mallon at gmx.de> 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 <stdio.h>
> > #include <stdlib.h>
> > #include <string.h>
> >
> > 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 at .
>


More information about the freebsd-current mailing list