LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-04-2003, 01:03 PM   #1
joewac
LQ Newbie
 
Registered: Aug 2003
Posts: 1

Rep: Reputation: 0
bug with free()


I am running Redhat Linux 7.2

I have a problem wherein a call to free() on a valid pointer returned from malloc() causes segmentation faults on subsequent calls to either malloc() or free().

Is there a known bug and fix for this problem?

Please note that this is NOT a case of calling free() a second time on the same pointer. This is basically a case where calls for heap management don't work after a call to free().

Here is an example of what willl cause the segmentation fault:

char * x;
char * y;

x = (char *)malloc(100);

....

free(x);

....


y = (char *)malloc(100);

segmentation fault




Here is another example:

char * x;
char * y;

x = (char *)malloc(100);
y = (char *)malloc(100);
....

free(x); <= OK
free(y); <= will cause a segmentation fault


Last edited by joewac; 08-04-2003 at 02:20 PM.
 
Old 08-04-2003, 02:13 PM   #2
Corin
Member
 
Registered: Jul 2003
Location: Jette, Brussels Hoofstedelijk Gewest
Distribution: Debian sid, RedHat 9, Suse 8.2
Posts: 446

Rep: Reputation: 31
You may only call free on a pointer referencing memory which you have allocated using malloc.

You may not call free a second time on memory which you have freed.

And yes malloc is know to be a somewhat buggy affair in some implementations. Have you done a web search on malloc?
 
Old 08-06-2003, 01:49 PM   #3
bastard23
Member
 
Registered: Mar 2003
Distribution: Debian
Posts: 275

Rep: Reputation: 30
joewac,

I suspect that you have an over/underrun on one of the buffers (x or y +100 somewhere). Use a malloc debugger. Glibc has some basic checks (set MALLOC_CHECK_=1 or 2). I just used efence, since I had it installed already. Just link it against the efence library. Or try out valgrind. It checks out all kinds of memory corruption problems.

Are you modifing x or y (not what it points to)?

Or post code that fails. The smaller the better. Maybe someone will look at it.

I doubt a glibc malloc bug like this would live very long. But hey, ya never know. This google search didn't pop up anything interesting. Try searching on your glibc version (execute /lib/libc.so, yeah executable library) to get the verbose details.

Good Luck,
chris
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
fdisk -- no free sectors available; i have a few gigs free??? lowpro2k3 Linux From Scratch 5 02-03-2009 12:43 AM
Free Software, Free Society: Selected Essays of Richard M. Stallman irfanhab Linux - General 1 11-09-2004 06:22 AM
Free Gillete Products + list of other free stuff looksmart123 General 1 08-08-2004 03:38 PM
Free86 bug or nVidia bug?? ProtoformX Linux - Software 2 05-12-2004 02:38 AM
Free, free,FREE=? no money, = Freedom? murshed Linux - Newbie 8 01-20-2003 07:01 AM


All times are GMT -5. The time now is 10:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration