Re: Segmentation fault at malloc.c:4232

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

 



On Sat, 1 Mar 2008 06:10:55 +0800, hanpingtian@xxxxxxxxx wrote:

> 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

Your theory is false, your code is broken. You really need to free()
the line buffer when it is allocated by getline(). But you call getline()
in a while-loop without resetting the line pointer to NULL. Here's the
fix:

--- compiler.c~ 2008-02-29 07:06:46.000000000 +0100
+++ compiler.c  2008-02-29 23:55:41.000000000 +0100
@@ -25,6 +25,7 @@
        }
 
        free(line);
+    line = NULL;
        STACKfree();
     }
 

-- 
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux