This is the mail archive of the
gdb@sources.redhat.com
mailing list for the GDB project.
Strange issue with mmalloc
- From: Javier Valencia <jvalencia at log01 dot org>
- To: gdb at sources dot redhat dot com
- Date: Wed, 04 May 2005 01:05:35 +0100
- Subject: Strange issue with mmalloc
Hi list, i'm new to mmalloc functions. I've found a strange issue when
calling malloc several times, it ends with a segmentation fault always
in the same point.
This is my example code: (note that the buffer file is created
externally with touch)
#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/types.h>
int main()
{
void *memory;
int fd;
int a;
char *tmp;
fd = open("./buffer", O_RDWR);
printf("%d\n", fd);
memory = mmalloc_attach(fd, NULL);
printf("%x\n", memory);
for(a=0; a<1000; a++)
{
tmp = (char*)mmalloc(memory, sizeof(char)*10);
printf("#");
fflush(NULL);
}
mmalloc_detach(memory);
return 0;
}
And this is the output:
3
4001a000
####################################################
####################################################
.
.
.
####################################################
############Segmentation fault
The gdb backtrace is:
Program received signal SIGSEGV, Segmentation fault.
0x40035e39 in ?? () from /lib/libc.so.6
(gdb) bt
#0 0x40035e39 in ?? () from /lib/libc.so.6
#1 0x40134820 in _IO_2_1_stdin_ () from /lib/libc.so.6
#2 0xbffff61c in ?? ()
#3 0x00000001 in ?? ()
I know that i'm not freeing the allocated memory.