c - "free(): invalid pointer" error and core dump -


i got unwanted output @ end of successful execution of program while freeing dynamic memory allocated dynamically.

*** glibc detected *** /home/ahor/desktop/project work/node: free(): invalid pointer: 0xb7fda000 *** ======= backtrace: ========= /lib/i386-linux-gnu/libc.so.6(+0x75ee2)[0xb7e93ee2] /home/ahor/desktop/project work/node[0x8048cf9] /lib/i386-linux-gnu/libc.so.6(__libc_start_main+0xf3)[0xb7e374d3] /home/ahor/desktop/project work/node[0x8048561] ======= memory map: ======== 08048000-0804a000 r-xp 00000000 08:06 786473     /home/ahor/desktop/project work/node 0804a000-0804b000 r--p 00001000 08:06 786473     /home/ahor/desktop/project work/node 0804b000-0804c000 rw-p 00002000 08:06 786473     /home/ahor/desktop/project work/node 0804c000-0806d000 rw-p 00000000 00:00 0          [heap] b7deb000-b7e07000 r-xp 00000000 08:06 2228253    /lib/i386-linux-gnu/libgcc_s.so.1 b7e07000-b7e08000 r--p 0001b000 08:06 2228253    /lib/i386-linux-gnu/libgcc_s.so.1 b7e08000-b7e09000 rw-p 0001c000 08:06 2228253    /lib/i386-linux-gnu/libgcc_s.so.1 b7e1d000-b7e1e000 rw-p 00000000 00:00 0  b7e1e000-b7fc1000 r-xp 00000000 08:06 2228351    /lib/i386-linux-gnu/libc-2.15.so b7fc1000-b7fc3000 r--p 001a3000 08:06 2228351    /lib/i386-linux-gnu/libc-2.15.so b7fc3000-b7fc4000 rw-p 001a5000 08:06 2228351    /lib/i386-linux-gnu/libc-2.15.so b7fc4000-b7fc7000 rw-p 00000000 00:00 0  b7fd7000-b7fd8000 rw-p 00000000 00:00 0  b7fd8000-b7fd9000 rw-s 00000000 00:04 12517386   /sysv001120bd (deleted) b7fd9000-b7fda000 rw-p 00000000 00:00 0  b7fda000-b7fdb000 rw-s 00000000 00:04 12484617   /sysv00307eff (deleted) b7fdb000-b7fdd000 rw-p 00000000 00:00 0  b7fdd000-b7fde000 r-xp 00000000 00:00 0          [vdso] b7fde000-b7ffe000 r-xp 00000000 08:06 2228363    /lib/i386-linux-gnu/ld-2.15.so b7ffe000-b7fff000 r--p 0001f000 08:06 2228363    /lib/i386-linux-gnu/ld-2.15.so b7fff000-b8000000 rw-p 00020000 08:06 2228363    /lib/i386-linux-gnu/ld-2.15.so bffdf000-c0000000 rw-p 00000000 00:00 0          [stack]  ...... ...... ...... 

i recieve message when track using gdb.

program received signal sigabrt, aborted. 0xb7fdd424 in __kernel_vsyscall () (gdb) bt #0  0xb7fdd424 in __kernel_vsyscall () #1  0xb7e4c1df in raise () /lib/i386-linux-gnu/libc.so.6 #2  0xb7e4f825 in abort () /lib/i386-linux-gnu/libc.so.6 #3  0xb7e8939a in ?? () /lib/i386-linux-gnu/libc.so.6 #4  0xb7e93ee2 in ?? () /lib/i386-linux-gnu/libc.so.6 #5  0x08048cf9 in main (argc=6, argv=0xbffff214) @ node.c:180 

...... ...... here's code segment affecting this? cannot detect cause, i'll grateful if can me.

// creating dynamic memory net     if((net = (struct dot **)malloc(v * sizeof(struct dot))) == null) {         perror("struct dot malloc() failed\n");         exit(1);     }     for(i = 0 ; < v; i++)         if((net[i] = (struct dot *)malloc(v * sizeof(struct dot))) == null) {         perror("net[i] malloc() failed.\n");         for(j = 0; j < i; j++)             free(net[j]);         free(net);               } ..... ..... // creating dynamic memory link_status     if((link_status = (struct link **)malloc(v * sizeof(struct link))) == null) {         perror("struct link malloc() failed\n");         exit(1);     }     for(i = 0 ; < v; i++)         if((link_status[i] = (struct link *)malloc(v * sizeof(struct link))) == null) {         perror("link_status[i] malloc() failed.\n");         for(j = 0; j < i; j++)             free(link_status[j]);         free(link_status);               } ...... 

the glibc detected free() function used below.

// free allocated dynamic memories     for(i = 0; < v; i++) {         free(net[i]);         free(link_status[i]);     }     free(net);     free(link_status); 

please me!

you overwriting memory not belong you. can use valgrind find code responsible bad write(s).


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -