OFFTOPIC : Re: segmentation fault

Try this :
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>

main()
{
while (1==1)
{
char * buffer = malloc(1000000);
if (buffer == NULL)
{
perror (“Error”);
*buffer = 2;
}
}
}

on my linux the allocation error quickly happens (on my solaris too), the
access to the buffer makes a segmentation fault. If you reduce the buffer
size the error will come later.

Julien> ----- Original Message -----

From: pontus.pihlgren.5501@student.uu.se (Pontus Pihlgren)
To:
Sent: Wednesday, February 26, 2003 11:02 AM
Subject: Re: [SDL] segmentation fault

How, out of curiosity, can a memory leak cause a segmentation fault?
I can see how it would generate an “out of memory”- error or, more likely,
cause
your os to start writing memorypages to disk. But I fail to see where it
would
cause a Segmentation fault.

/Pontus

Maybe, you have memory leaks. Are you freeing each unused memory area ?

Julien

----- Original Message -----
From: “Samuel” <taxtropel_news at yahoo.com>
To:
Sent: Wednesday, February 26, 2003 9:40 AM
Subject: Re: [SDL] segmentation fault


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

On Wed Feb 26, 2003 at 11:55:00AM +0100, the boisterous
Julien Pauty
wrote to me:

char * buffer = malloc(1000000);
if (buffer == NULL)
{
  perror ("Error");
  *buffer = 2;
}

You are trying to access a buffer which points to NULL. This has nothing
to do with your memory leak. It’s obvious that this is a nogo.

so long
Thomas–
___ Obviously we do not want to leave zombies around.
/\ - W. Richard Stevens
( ^ > Thomas Krennwallner
/ \ 1024D/67A1DA7B 9484 D99D 2E1E 4E02 5446 DAD9 FF58 4E59 67A1 DA7B
(
/) http://bigfish.ull.at/~djmaecki/
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20030226/c7dc8d70/attachment.pgp

Yes I know, that it will do a segmentation fault. The goal of the example
was to show that if you request too much memory without testing the returned
pointer you will have a segfault. I just wanted to say that, maybe the video
player doesn’t free unused memory, which can lead to an allocation error.
Then if you don’t test the returned pointer you will have a segfault.

It was just a supposition.

Julien> ----- Original Message -----

From: djmaecki@ull.at (Thomas Krennwallner)
To:
Sent: Wednesday, February 26, 2003 12:06 PM
Subject: Re: OFFTOPIC : Re: [SDL] segmentation fault