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

@ -203,7 +203,10 @@ mapped_ring_buffer_new_reader (size_t buffer_size)
header->offset = page_size;
header->size = buffer_size - page_size;
self = g_slice_new0 (MappedRingBuffer);
self = sysprof_malloc0 (sizeof (MappedRingBuffer));
if (self == NULL)
return NULL;
self->ref_count = 1;
self->mode = MODE_READER;
self->body_size = buffer_size - page_size;
@ -301,7 +304,14 @@ mapped_ring_buffer_new_writer (int fd)
return NULL;
}
self = g_slice_new0 (MappedRingBuffer);
self = sysprof_malloc0 (sizeof (MappedRingBuffer));
if (self == NULL)
{
munmap (map, page_size + ((buffer_size - page_size) * 2));
close (fd);
return NULL;
}
self->ref_count = 1;
self->mode = MODE_WRITER;
self->fd = fd;