LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   malloc error: glibc (http://www.linuxquestions.org/questions/linux-general-1/malloc-error-glibc-449563/)

vdhussa 05-29-2006 06:07 AM

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

timmeke 05-29-2006 08:25 AM

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?

slzckboy 05-29-2006 09:29 AM

run the program under Valgrind.

www.valgrind.org if u are unfamiliar.

vdhussa 05-29-2006 01:41 PM

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!!!

timmeke 05-30-2006 02:07 AM

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.

vdhussa 05-30-2006 05:13 AM

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

timmeke 05-30-2006 07:05 AM

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?

slzckboy 05-30-2006 07:43 AM

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.

vdhussa 05-30-2006 10:42 AM

K.. emerging valgrind... will post how it works! Thanx

vdhussa 05-31-2006 09:22 AM

Thanx a lot everybody... Got some serious memory leaks using valgrind. Everything working amazingly now!

slzckboy 05-31-2006 09:47 AM

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


All times are GMT -5. The time now is 08:45 AM.