Skip to content

Commit 5e499f5

Browse files
committed
BUG: add missing checks for nullptr in mm_new(|_nan)
1 parent 8e7c00e commit 5e499f5

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

bottleneck/src/move_median/move_median.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,16 @@ static inline void mm_swap_heap_heads(mm_node **s_heap, idx_t n_s,
5959
* heap). The handle, containing information about the heaps, is returned. */
6060
mm_handle *
6161
mm_new(const idx_t window, idx_t min_count) {
62-
mm_handle *mm = malloc(sizeof(mm_handle));
62+
mm_handle *mm = malloc(sizeof(mm_handle));
63+
if (mm == NULL) return NULL;
6364
mm->nodes = malloc(window * sizeof(mm_node*));
6465
mm->node_data = malloc(window * sizeof(mm_node));
66+
if (mm->nodes == NULL || mm->node_data == NULL) {
67+
free(mm->node_data);
68+
free(mm->nodes);
69+
free(mm);
70+
return NULL;
71+
}
6572

6673
mm->s_heap = mm->nodes;
6774
mm->l_heap = &mm->nodes[window / 2 + window % 2];
@@ -168,8 +175,15 @@ mm_update(mm_handle *mm, ai_t ai) {
168175
mm_handle *
169176
mm_new_nan(const idx_t window, idx_t min_count) {
170177
mm_handle *mm = malloc(sizeof(mm_handle));
178+
if (mm == NULL) return NULL;
171179
mm->nodes = malloc(2 * window * sizeof(mm_node*));
172180
mm->node_data = malloc(window * sizeof(mm_node));
181+
if (mm->nodes == NULL || mm->node_data == NULL) {
182+
free(mm->node_data);
183+
free(mm->nodes);
184+
free(mm);
185+
return NULL;
186+
}
173187

174188
mm->s_heap = mm->nodes;
175189
mm->l_heap = &mm->nodes[window / 2 + window % 2];

0 commit comments

Comments
 (0)