LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-29-2006, 06:07 AM   #1
vdhussa
LQ Newbie
 
Registered: Dec 2004
Location: New Delhi
Distribution: Gentoo
Posts: 8

Rep: Reputation: 0
malloc error: glibc


I have maed a dijkstra implementation with a fibonacci heap priority queue. In case of small inputs its working fine but if the graph is large (5000 vertices) then am getting the error:

glibc-detected** malloc(): memory corruption:0x0805f968
Aborted

I have glibc 2.5.3 on a suse 10 system.

Please help
 
Old 05-29-2006, 08:25 AM   #2
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
Have you tried debugging your app with "ddd" or "gdb"?

Malloc only allocates memory dynamically, for later use.

Can you estimate how many memory you're trying to use/allocate for your code?
 
Old 05-29-2006, 09:29 AM   #3
slzckboy
Member
 
Registered: May 2005
Location: uk - Reading
Distribution: slackware 14.2 kernel 4.19.43
Posts: 462

Rep: Reputation: 30
run the program under Valgrind.

www.valgrind.org if u are unfamiliar.
 
Old 05-29-2006, 01:41 PM   #4
vdhussa
LQ Newbie
 
Registered: Dec 2004
Location: New Delhi
Distribution: Gentoo
Posts: 8

Original Poster
Rep: Reputation: 0
Yup, used gdb. I got the exact place only after using the debugger. The error comes when am allocating memory of a new node to be inserted.

fibNode *newNode = (fibNode*)malloc(sizeof(fibNode));

I know there's nothing wrong here as it is working for less number of nodes. I am using a sparse graph representation. So i don't think memory should be a problem. Its not my code that's causing trouble!!!
 
Old 05-30-2006, 02:07 AM   #5
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
Quote:
Originally Posted by vdhussa
fibNode *newNode = (fibNode*)malloc(sizeof(fibNode));
This allocation code seems fine and relatively standard.

Can you also post your de-allocation code (ie the corresponding "free")?
Are you sure that all your nodes get de-allocated properly?

Linking against libefence (Electric Fence) and then running your program again
with in the debugger may show memory problems.
 
Old 05-30-2006, 05:13 AM   #6
vdhussa
LQ Newbie
 
Registered: Dec 2004
Location: New Delhi
Distribution: Gentoo
Posts: 8

Original Poster
Rep: Reputation: 0
This comes up right in the begining! Right before any de-allocation. The first node getting allocated for the heap. Before this, structure for the graph is allocated. I'll try the lib u suggested. Thnx
 
Old 05-30-2006, 07:05 AM   #7
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
Maybe there's something wrong with your graph structure allocation (or any previous code) then.
Can you verify -via your debugger- that the memory pointers (ie for nodes & graph structure) are valid and that memory is allocated?
 
Old 05-30-2006, 07:43 AM   #8
slzckboy
Member
 
Registered: May 2005
Location: uk - Reading
Distribution: slackware 14.2 kernel 4.19.43
Posts: 462

Rep: Reputation: 30
I still think that Valgrind is your best bet,although linking in with electric fence(a.k.a duma) should do the job too I guess.As timmeke pointed out looks like its the preceeding code which is corrupting your memory so you need to try and catch(duma) or record (valgrind) the problem earlier.
 
Old 05-30-2006, 10:42 AM   #9
vdhussa
LQ Newbie
 
Registered: Dec 2004
Location: New Delhi
Distribution: Gentoo
Posts: 8

Original Poster
Rep: Reputation: 0
K.. emerging valgrind... will post how it works! Thanx
 
Old 05-31-2006, 09:22 AM   #10
vdhussa
LQ Newbie
 
Registered: Dec 2004
Location: New Delhi
Distribution: Gentoo
Posts: 8

Original Poster
Rep: Reputation: 0
Thanx a lot everybody... Got some serious memory leaks using valgrind. Everything working amazingly now!
 
Old 05-31-2006, 09:47 AM   #11
slzckboy
Member
 
Registered: May 2005
Location: uk - Reading
Distribution: slackware 14.2 kernel 4.19.43
Posts: 462

Rep: Reputation: 30
Valgrind is great,(IMO.)I can't recommend it enough.
Great to hear that all is working.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
*** glibc detected *** malloc() / free()/ double RohanShrivastav Programming 12 10-01-2012 10:08 AM
glibc detected *** malloc(): memory corruption: abefroman Linux - Software 2 04-12-2006 12:12 PM
error in glibc faraday83 Linux From Scratch 3 10-10-2004 11:23 PM
glibc error xlordt Linux - Newbie 3 08-07-2004 11:56 PM
gdbm malloc error Sammy2ooo Linux - Software 0 11-07-2003 04:50 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration