LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-07-2004, 04:58 AM   #1
spuzzzzzzz
Member
 
Registered: Sep 2003
Location: Australia
Distribution: Gentoo
Posts: 465

Rep: Reputation: 30
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.
 
Old 07-07-2004, 10:16 AM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 58
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.
 
Old 07-07-2004, 06:41 PM   #3
spuzzzzzzz
Member
 
Registered: Sep 2003
Location: Australia
Distribution: Gentoo
Posts: 465

Original Poster
Rep: Reputation: 30
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.
 
Old 07-07-2004, 06:52 PM   #4
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
most likely you're corrupting heap memory somewhere. use the valgrind program to see where.
 
Old 07-08-2004, 01:37 AM   #5
spuzzzzzzz
Member
 
Registered: Sep 2003
Location: Australia
Distribution: Gentoo
Posts: 465

Original Poster
Rep: Reputation: 30
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...

Last edited by spuzzzzzzz; 07-08-2004 at 02:04 AM.
 
Old 07-08-2004, 04:31 PM   #6
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
heheh heh of course i think we've all done that. and yea valgrind kicks ass, thanks to someone on here for mentioning that.
 
Old 07-08-2004, 06:03 PM   #7
spuzzzzzzz
Member
 
Registered: Sep 2003
Location: Australia
Distribution: Gentoo
Posts: 465

Original Poster
Rep: Reputation: 30
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Gate 88 segfault t3gah Linux - Games 1 03-21-2005 04:07 AM
grep, ln both segfault TexasDex Linux - Software 1 03-20-2005 05:46 PM
segfault prob in C zaichik Programming 5 01-25-2005 07:00 AM
lsmod segfault? z-vet Yoper 6 12-15-2004 03:40 PM
segfault with fglrx Vyeperman Linux - Hardware 0 04-17-2004 11:06 PM


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

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration