*** glibc detected *** ./a.out: malloc(): memory corruption (fast):

*** glibc detected *** ./a.out: malloc(): memory corruption (fast):

Posted A minute ago
M trying to make multiway tree and dont know what happend when this part of code get executed:
01void ins(NODE *ptr)
02{
03 //working
04 if(ptr!=NULL)
05 {
06 SNODE *var=NULL;
07 var=(SNODE *)malloc(sizeof(SNODE));
08 var->next=start;
09 start=var;
10 var->info=ptr;
11 }//end if
12}//end ins()

error :

*** glibc detected *** ./a.out: malloc(): memory corruption (fast): 0x08bde038 ***
======= Backtrace: =========
/lib/i386-linux-gnu/libc.so.6(+0x6ebc2)[0xb76a7bc2]
/lib/i386-linux-gnu/libc.so.6(+0x70cf3)[0xb76a9cf3]
/lib/i386-linux-gnu/libc.so.6(__libc_calloc+0xae)[0xb76ac4ce]
./a.out[0x80485f9]
./a.out[0x8048985]
./a.out[0x8048ce4]
/lib/i386-linux-gnu/libc.so.6(__libc_start_main+0xf3)[0xb7652113]
./a.out[0x80484c1]
======= Memory map: ========
08048000-0804a000 r-xp 00000000 08:01 117539 /home/utkarsh/Desktop/c-code/Data_structures/trees/a.out
0804a000-0804b000 r--p 00001000 08:01 117539 /home/utkarsh/Desktop/c-code/Data_structures/trees/a.out
0804b000-0804c000 rw-p 00002000 08:01 117539 /home/utkarsh/Desktop/c-code/Data_structures/trees/a.out
08bde000-08bff000 rw-p 00000000 00:00 0 [heap]
b7500000-b7521000 rw-p 00000000 00:00 0
b7521000-b7600000 ---p 00000000 00:00 0
b7605000-b7621000 r-xp 00000000 08:01 94286 /lib/i386-linux-gnu/libgcc_s.so.1
b7621000-b7622000 r--p 0001b000 08:01 94286 /lib/i386-linux-gnu/libgcc_s.so.1
b7622000-b7623000 rw-p 0001c000 08:01 94286 /lib/i386-linux-gnu/libgcc_s.so.1
b7638000-b7639000 rw-p 00000000 00:00 0
b7639000-b77af000 r-xp 00000000 08:01 94290 /lib/i386-linux-gnu/libc-2.13.so
b77af000-b77b1000 r--p 00176000 08:01 94290 /lib/i386-linux-gnu/libc-2.13.so
b77b1000-b77b2000 rw-p 00178000 08:01 94290 /lib/i386-linux-gnu/libc-2.13.so
b77b2000-b77b5000 rw-p 00000000 00:00 0
b77c8000-b77cc000 rw-p 00000000 00:00 0
b77cc000-b77cd000 r-xp 00000000 00:00 0 [vdso]
b77cd000-b77eb000 r-xp 00000000 08:01 94287 /lib/i386-linux-gnu/ld-2.13.so
b77eb000-b77ec000 r--p 0001d000 08:01 94287 /lib/i386-linux-gnu/ld-2.13.so
b77ec000-b77ed000 rw-p 0001e000 08:01 94287 /lib/i386-linux-gnu/ld-2.13.so
bfd86000-bfda7000 rw-p 00000000 00:00 0 [stack]
Aborted

pls guys tell me exactly what happend and what does the error massage means and also a solution pls.

thanks!!

'var' should be initialized or assigned a value.

i already did that

SNODE *var=NULL;

I don't see anything obviously wrong with your code, but you use lots of variables you don't show being defined, so it's very difficult to say. Post more of your code.

Since you're dealing with structures of pointers it's possible for a bug earlier to crash the code later -- a bad pointer gets stored, and the crash only happens when you use the bad value...