Skip to content

Commit

Permalink
Add assertions after every memory allocation that may fail.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Oct 3, 2024
1 parent 59a4129 commit 3485121
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ext/io/event/selector/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ inline static void IO_Event_Array_allocate(struct IO_Event_Array *array, size_t
{
if (count) {
array->base = (void**)calloc(count, sizeof(void*));
assert(array->base);

array->count = count;
} else {
array->base = NULL;
Expand All @@ -51,6 +53,7 @@ inline static void IO_Event_Array_free(struct IO_Event_Array *array)
void *element = array->base[i];
if (element) {
array->element_free(element);

free(element);
}
}
Expand Down Expand Up @@ -107,6 +110,7 @@ inline static void* IO_Event_Array_lookup(struct IO_Event_Array *array, size_t i
// Allocate the element if it doesn't exist:
if (*element == NULL) {
*element = malloc(array->element_size);
assert(*element);

if (array->element_initialize) {
array->element_initialize(*element);
Expand Down
1 change: 1 addition & 0 deletions ext/io/event/selector/selector.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ VALUE IO_Event_Selector_raise(struct IO_Event_Selector *backend, int argc, VALUE
void IO_Event_Selector_queue_push(struct IO_Event_Selector *backend, VALUE fiber)
{
struct IO_Event_Selector_Queue *waiting = malloc(sizeof(struct IO_Event_Selector_Queue));
assert(waiting);

waiting->head = NULL;
waiting->tail = NULL;
Expand Down

0 comments on commit 3485121

Please sign in to comment.