LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   segfault in mallopt() (http://www.linuxquestions.org/questions/programming-9/segfault-in-mallopt-202082/)

spuzzzzzzz 07-07-2004 05:58 AM

segfault in mallopt()
 
I'm trying to write a c/gtk+ program, but I keep getting segfaults in mallopt() from /lib/libc.so.6. I've narrowed the offending code down to a call to gdk_create_pixmap_from_xpm(). How can I find out more? Do I have a bug in one of my libs? Or am I doing something wrong?

I'm running gentoo, with gtk+ version 2.4.1 and glibc version 2.3.3.20040420.

itsme86 07-07-2004 11:16 AM

Most likely you're doing something wrong. Try using gdb on the dumped core file. From there you can 'bt' to see how the functions were called. Type 'up' until you enter a function in your program (gdb will probably start in a function from the gtk+ lib). Then you can type 'p <variable name>' on the varibles you passed to that gtk pixmap function to show what the variables actually were at that point. You might discover something unexpected.

spuzzzzzzz 07-07-2004 07:41 PM

This is what I get when I gdb the core dump:
Code:

Program terminated with signal 11, Segmentation fault.
#0  0x4053cebf in ?? ()
(gdb) bt
#0  0x4053cebf in ?? ()
Cannot access memory at address 0xbfffe824
(gdb) up
Initial frame selected; you cannot go up.
(gdb)

if I load the program and run it:
Code:

Program received signal SIGSEGV, Segmentation fault.
0x4053cebf in mallopt () from /lib/libc.so.6
(gdb) bt
#0  0x4053cebf in mallopt () from /lib/libc.so.6
#1  0x4053c64e in mallopt () from /lib/libc.so.6
#2  0x4053b871 in malloc () from /lib/libc.so.6
#3  0x4053ba9b in realloc () from /lib/libc.so.6
#4  0x40489c54 in g_realloc () from /usr/lib/libglib-2.0.so.0
(gdb) up
#1  0x4053c64e in mallopt () from /lib/libc.so.6
(gdb) up
#2  0x4053b871 in malloc () from /lib/libc.so.6
(gdb) up
#3  0x4053ba9b in realloc () from /lib/libc.so.6
(gdb) up
#4  0x40489c54 in g_realloc () from /usr/lib/libglib-2.0.so.0
(gdb) up
Initial frame selected; you cannot go up.
(gdb)

I'm kind of a noob at gdb, but I always thought that the initial frame was the main() function. Maybe this has something to do with the fact that gtk+ was compiled with -fomit-frame-pointer?

Btw, I don't call g_realloc() from anywhere in my program.

infamous41md 07-07-2004 07:52 PM

most likely you're corrupting heap memory somewhere. use the valgrind program to see where.

spuzzzzzzz 07-08-2004 02:37 AM

Will do, thanks.

I was obssessed with the gdk_create_pixmap_from_xpm() call because that's where the segfaults were actually happening - I hadn't thought of the whole heap corruption thing.

edit:
OMG OMG OMG, I'm such an IDIOT!!!! Can someone please tell me they've done this too, so I won't feel quite so stupid?
Code:

g_malloc(sizeof(struct xxx *))
instead of
Code:

g_malloc(sizeof(struct xxx))
Btw, valgrind is a really useful program - I can't believe I've never heard of it before...

infamous41md 07-08-2004 05:31 PM

heheh heh of course i think we've all done that. and yea valgrind kicks ass, thanks to someone on here for mentioning that.

spuzzzzzzz 07-08-2004 07:03 PM

Quote:

and yea valgrind kicks ass, thanks to someone on here for mentioning that.
I believe it was you that mentioned it :P

Thanks everyone for your help - I should have said that before, but I was too wrapped up in my own idiocy ;)


All times are GMT -5. The time now is 05:10 AM.