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

@ -62,8 +62,20 @@
# include <sys/sendfile.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
static inline void *
sysprof_malloc0 (size_t size)
{
void *ptr = malloc (size);
if (ptr == NULL)
return NULL;
memset (ptr, 0, size);
return ptr;
}
#ifdef __linux__
# define _sysprof_getpagesize() getpagesize()
# define _sysprof_pread(a,b,c,d) pread(a,b,c,d)