Re: Segmentation fault at malloc.c:4232

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I just found out when I comment out the line 27, which calls free() to
free the line got from
getline(), the program doesn't segmentation fault.

But the manual of getline() tells us to free the "*lineptr" when it is
NULL before call getline(). It's the situation in my program.

With this src.txt:
(x = 1)
1
it reports "double free or corruption" when doesn't comment line 27:

*** glibc detected *** ./compiler: double free or corruption (!prev): 0x08c0d2d8
======= Backtrace: =========
/lib/libc.so.6[0x617ac1]
/lib/libc.so.6(cfree+0x90)[0x61b0f0]
./compiler[0x8048660]
/lib/libc.so.6(__libc_start_main+0xe0)[0x5c4390]
./compiler[0x8048451]
======= Memory map: ========
00110000-00111000 r-xp 00110000 00:00 0          [vdso]
0058f000-005aa000 r-xp 00000000 fd:00 51555      /lib/ld-2.7.so
005aa000-005ab000 r-xp 0001a000 fd:00 51555      /lib/ld-2.7.so
005ab000-005ac000 rwxp 0001b000 fd:00 51555      /lib/ld-2.7.so
005ae000-00701000 r-xp 00000000 fd:00 51556      /lib/libc-2.7.so
00701000-00703000 r-xp 00153000 fd:00 51556      /lib/libc-2.7.so
00703000-00704000 rwxp 00155000 fd:00 51556      /lib/libc-2.7.so
00704000-00707000 rwxp 00704000 00:00 0
00dee000-00df9000 r-xp 00000000 fd:00 51568
/lib/libgcc_s-4.1.2-20070925.so.1
00df9000-00dfa000 rwxp 0000a000 fd:00 51568
/lib/libgcc_s-4.1.2-20070925.so.1
08048000-08049000 r-xp 00000000 fd:01 4259848
/home/hpt/temp/algorithms_in_c/4.17/compiler
08049000-0804a000 rw-p 00000000 fd:01 4259848
/home/hpt/temp/algorithms_in_c/4.17/compiler
08c0d000-08c2e000 rw-p 08c0d000 00:00 0
b7e00000-b7e21000 rw-p b7e00000 00:00 0
b7e21000-b7f00000 ---p b7e21000 00:00 0
b7f2a000-b7f2c000 rw-p b7f2a000 00:00 0
b7f3c000-b7f3e000 rw-p b7f3c000 00:00 0
bf943000-bf958000 rw-p bffea000 00:00 0          [stack]
Aborted


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux