LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   bug with free() (https://www.linuxquestions.org/questions/linux-software-2/bug-with-free-78933/)

joewac 08-04-2003 01:03 PM

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


Corin 08-04-2003 02:13 PM

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?

bastard23 08-06-2003 01:49 PM

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


All times are GMT -5. The time now is 11:52 AM.