mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
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:
@ -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;
|
||||
|
||||
Reference in New Issue
Block a user