Re: memory problems

Alan Cox (alan@lxorguk.ukuu.org.uk)
Fri, 25 Jul 1997 09:38:00 +0100 (BST)


> application (with audio and video) that requires a lot of memory. It
> works
> fine for a certian period of time and crashes (dumps core). It has
> turned
> out be that the seg fault occurs in a malloc routine. The application
> can no longer get memory !! inspite of the fact that there is 128 Mbyte
> of

Most likely your program is buggy.

> SWAP available and NONE has been used. The output of "free" indicates
> that
> most of the memory is sitting in "cache" or "buffers". As I understand,
> this
> memory should be available for reuse, but just does not show up under
> "free".

Yep. Its for free.

> the kernel implementation (this particular version) wherein the cached
> memory
> does not get released for reuse ???.

Not in 2.0.29 - and you'd see "Cannot get a free page" messages everywhere
if you did hit out of memory cases. No most likely your program does
something somewhere like

x=malloc(strlen(str));
strcpy(x,str)

That happens to work when you overrun the first byte past a malloc block
on solaris but not on some other systems. Freeing the same thing twice is
also a "you might get away with it". Try running your program linked
with electric fence (gcc blah -lwhatever -lefence) - if you need electric
fence its on sunsite, and also available in rpm and deb archive formats
too