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

@ -75,6 +75,7 @@
#include "mapped-ring-buffer.h"
#include "sysprof-capture-util-private.h"
#include "sysprof-collector.h"
#define MAX_UNWIND_DEPTH 128
@ -214,7 +215,7 @@ sysprof_collector_free (void *data)
mapped_ring_buffer_unref (buffer);
}
g_free (collector);
free (collector);
}
}
@ -238,9 +239,12 @@ sysprof_collector_get (void)
g_private_replace (&collector_key, COLLECTOR_INVALID);
self = sysprof_malloc0 (sizeof (SysprofCollector));
if (self == NULL)
return COLLECTOR_INVALID;
G_LOCK (control_fd);
self = g_new0 (SysprofCollector, 1);
self->pid = getpid ();
#ifdef __linux__
self->tid = syscall (__NR_gettid, 0);