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 "sysprof-capture-condition.h"
#include "sysprof-capture-cursor.h"
#include "sysprof-capture-reader.h"
#include "sysprof-capture-util-private.h"
#define READ_DELEGATE(f) ((ReadDelegate)(f))
@ -81,7 +82,7 @@ sysprof_capture_cursor_finalize (SysprofCaptureCursor *self)
{
g_clear_pointer (&self->conditions, g_ptr_array_unref);
g_clear_pointer (&self->reader, sysprof_capture_reader_unref);
g_slice_free (SysprofCaptureCursor, self);
free (self);
}
static SysprofCaptureCursor *
@ -89,7 +90,10 @@ sysprof_capture_cursor_init (void)
{
SysprofCaptureCursor *self;
self = g_slice_new0 (SysprofCaptureCursor);
self = sysprof_malloc0 (sizeof (SysprofCaptureCursor));
if (self == NULL)
return NULL;
self->conditions = g_ptr_array_new_with_free_func ((GDestroyNotify) sysprof_capture_condition_unref);
self->ref_count = 1;