This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]