libsysprof-capture: Use malloc() rather than g_new0() and friends

Another step away from GLib. This changes the OOM behaviour of the
library — previously it would immediately `abort()` on OOM. However, it
seems likely that given the small number of allocations
libsysprof-capture does, it should be able to recover from an OOM
situation more gracefully than larger libraries can — so the new
implementation tries to do that.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #40
This commit is contained in:
Philip Withnall
2020-07-01 17:24:50 +01:00
parent 6e281dca1f
commit b0a5c4f700
7 changed files with 86 additions and 18 deletions

View File

@ -63,6 +63,7 @@
#include <string.h>
#include "sysprof-capture-condition.h"
#include "sysprof-capture-util-private.h"
#include "sysprof-macros-internal.h"
/**
@ -204,7 +205,10 @@ sysprof_capture_condition_init (void)
{
SysprofCaptureCondition *self;
self = g_slice_new0 (SysprofCaptureCondition);
self = sysprof_malloc0 (sizeof (SysprofCaptureCondition));
if (self == NULL)
return NULL;
self->ref_count = 1;
return g_steal_pointer (&self);
@ -294,7 +298,7 @@ sysprof_capture_condition_finalize (SysprofCaptureCondition *self)
break;
}
g_slice_free (SysprofCaptureCondition, self);
free (self);
}
SysprofCaptureCondition *