mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2026-02-10 07:00:53 +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:
@ -181,8 +181,8 @@ sysprof_capture_writer_finalize (SysprofCaptureWriter *self)
|
||||
self->fd = -1;
|
||||
}
|
||||
|
||||
g_free (self->buf);
|
||||
g_free (self);
|
||||
free (self->buf);
|
||||
free (self);
|
||||
}
|
||||
}
|
||||
|
||||
@ -483,10 +483,18 @@ sysprof_capture_writer_new_from_fd (int fd,
|
||||
/* This is only useful on files, memfd, etc */
|
||||
if (ftruncate (fd, 0) != 0) { /* Do Nothing */ }
|
||||
|
||||
self = g_new0 (SysprofCaptureWriter, 1);
|
||||
self = sysprof_malloc0 (sizeof (SysprofCaptureWriter));
|
||||
if (self == NULL)
|
||||
return NULL;
|
||||
|
||||
self->ref_count = 1;
|
||||
self->fd = fd;
|
||||
self->buf = (guint8 *)g_malloc0 (buffer_size);
|
||||
self->buf = (uint8_t *) sysprof_malloc0 (buffer_size);
|
||||
if (self->buf == NULL)
|
||||
{
|
||||
free (self);
|
||||
return NULL;
|
||||
}
|
||||
self->len = buffer_size;
|
||||
self->next_counter_id = 1;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user