lkml.org 
[lkml]   [1999]   [Dec]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRecursive malloc crashing Linux. (Well almost)
Date
Hi

A friend of mine actually tried a small program which had a recursive function
with malloc in it, In which unknowingly he had forgotten to terminate the
recursion thus going into a infinite recursion.

When he ran this program , it used to seg fault , but at the same time he found
that he had lost space in his hard disk. This was inspite of removing the
Core Dumps it generated.

NOTE: __ the programs were run as normal user __

When he asked me, I also wrote a similar program and tried on my m/c. Strangly
enough I got 2 behaviours.
a) Sometimes it gives a Bus error
b) Sometimes everything almost hangs. I mean It starts giving
***********
Out of memory for Init (or klogd or sendmail or so on.)
************
Also the system becomes almost unresponsive. Finaly I am forced to reset the
m/c. (Well I didn't wait for more than 10 minutes, may be if I wait more
something might happen).

Even I noticed losing some space. But fsck doesn't give any error. Also I
wasn't able to reproduce it later so not very sure of this.

This seemed strange enough so I thought I check if anyone else has noticed this
before.

Well isn't the memory allocation logic such (or shouldn't it be ) that if a
process starts to ask beyond a certain amount of total memory it stops giving
any more memory to the process or so.

*************** the Culprit code ***************

void recurse(void)
{
malloc(4096*1024);
recurse();
}

int main()
{
recurse();
return 0;
}

NOTE: If I comment out the malloc above then the program segfaults almost
immidiately, Seems to be because of stack overflow which is valid.

****************the test m/cs **********************

AMD k6-2 350
64 MB RAM
Kernel that came with Redhat 6.1 which was recompiled
120MB of swap.

*******************************************************

I don't have 2.2.13 kernel at office currently. And the 2.3.29 kernel which I
have requires the 2.3.x modutils and so , which I haven't downloaded yet. And
as this error seemed strange enough I thought I ask immidiately rather than
waiting till tomorrow so that I can check it with the 2.2.13 kernel at home.


---------
Keep :-)
HanishKVC
http://HanishKVC.tripod.com/


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:55    [W:0.064 / U:0.356 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site