naemon/naemon-core — pull request #70 by catharsis (2014-06-18 14:37:30+00:00)
Title: Abort when memory allocation fails

This patch adds an aborting implementation of the following functions:

malloc
calloc
realloc
strdup
strndup
asprintf

and changes all calls to them to their aborting counterpart (prefixed by
nm_, e.g nm_malloc).

Why? Because we really, really, really don't handle
memory allocation failure gracefully at all, ever. Maybe we want to
pretend that we do by doing:

if ( ptr = malloc(sizeof(foo)) == NULL)
return NULL;

But how is anyone supposed to know that we just ran out of memory from
that? Not that it matters since naemon is not designed to degrade
gracefully *anyway*. What would we do if we somehow successfully
identified that we have no memory? It's not like we can do anything
worthwhile anyways, say, like running checks or sending notifications or
...

This has the positive side effect of getting rid of a lot of pointless
complexity and silencing a whole bunch of warnings about "unused return
values" and the like. See #69.

Anyhow, the aforementioned checks for MA failure were not really that
common anyway, meaning that an actual scenario where we had really run
OOM would be more likely to result in a segfault than anything else.

In all, I could find *one* place where we actually did something
productive in case memory was not returned, namely when we were about to
start a new worker. And what did we do then? Log it. And abort.

In conclusion, we no longer hide/escalate errors for "someone else" to
deal with for any value of "someone else" that equals "noone".

goto endrant;

This partially fixes #69.

Signed-off-by: Anton Lofgren