Re: You don't check for malloc failure

Maarten Bezemer <[email protected]>
Newsgroups gmane.comp.audio.icecast.devel
Message-ID <[email protected]>
Hi,

> On Fri, 2011-04-29 at 09:05 +0200, Peter J. Philipp wrote:
>> You don't check for malloc failure.  I've made a patch that is possibly
>> wrong but it saves the program from SIGSEGV and replaces it with SIGABRT.

On Fri, 29 Apr 2011, Philipp Schafft wrote:
> But I have a question:
> Not all of them (only had a brief look at the patch) look to be in a
> 'safe' startup/shutdown state but code wich is run within the normal
> operation. Wouldn't it be better to handle those cases in a diffrent way
> because abort() will kill the process? Currently if it derefences NULL
> the kernel will kill the process (very likely). This patch would improve
> the situation because the behavor will be more defined wich is a big pro
> already.

Most implementations of malloc() don't return NULL except for very obvious 
cases of bad programming.
When memory is running out, malloc() may return a valid pointer, but 
writing anything in the malloc-ed data region can still result in the 
kernel killing the process.

So, although I think checking the return values is a good thing, this is 
no guarantee at all that things will always run as expected.
(Besides, when running icecast on a Linux box, there's always the risk of 
being killed by the OOM killer even when you're not doing anything wrong.)


Just my 2 cents..

-- 
Maarten
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.