lkml.org 
[lkml]   [2000]   [Aug]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectMemory management...
Howdi friends,
I'm a bit new to linux, and perhaps don't belong on this mail list, but I've run across something that I just don't see as right. Here's some code I put together that has no problem bringing kernel 2.2.5-15 to it's knees even when run without any special priveleges. what's the situation?

Here's the code:

// Tested on kernel 2.2.5-15, this code crashes the system by allocating
// all system memory and writing data to it.

#include <stdlib.h>
#include <stdio.h>

void main(void)
{
unsigned long int mem = (1024 * 1024) + 1;
int i = 0;
char * data[10];
unsigned long int loop;

printf("Finding max memory allocatable...");
do
{
mem--;
data[i] = malloc(mem * 1024);
if(data[i] != NULL)
{
printf("Allocated %dKB of memory.\n", mem);
printf("Filling with 0x00...");
for(loop = 0; loop < mem * K; loop++) *(data[i] + loop) = 0x00;
printf("done.\n");
i++;
}
}
while(mem != 0);
printf("All memory allocated.\n");
printf("Press <ENTER> to free memory...\n");
getchar();
while(i != 0)
{
free(data[i]);
i--;
}
printf("Memory freed. Goodbye.\n");
return;
}

**********
Thanks for your time,

Christopher George


----------------------------------------------------------------
Get your free email from AltaVista at http://altavista.iname.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:57    [W:0.041 / U:0.508 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site