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

@ -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;