From 5e499f5e336e14c9e23ec42b1247269f5ecc3f35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Robert?= Date: Fri, 3 Apr 2026 15:36:29 +0200 Subject: [PATCH] BUG: add missing checks for nullptr in `mm_new(|_nan)` --- bottleneck/src/move_median/move_median.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/bottleneck/src/move_median/move_median.c b/bottleneck/src/move_median/move_median.c index 3f0709abe4..04d7f5464b 100644 --- a/bottleneck/src/move_median/move_median.c +++ b/bottleneck/src/move_median/move_median.c @@ -59,9 +59,16 @@ static inline void mm_swap_heap_heads(mm_node **s_heap, idx_t n_s, * heap). The handle, containing information about the heaps, is returned. */ mm_handle * mm_new(const idx_t window, idx_t min_count) { - mm_handle *mm = malloc(sizeof(mm_handle)); +mm_handle *mm = malloc(sizeof(mm_handle)); + if (mm == NULL) return NULL; mm->nodes = malloc(window * sizeof(mm_node*)); mm->node_data = malloc(window * sizeof(mm_node)); + if (mm->nodes == NULL || mm->node_data == NULL) { + free(mm->node_data); + free(mm->nodes); + free(mm); + return NULL; + } mm->s_heap = mm->nodes; mm->l_heap = &mm->nodes[window / 2 + window % 2]; @@ -168,8 +175,15 @@ mm_update(mm_handle *mm, ai_t ai) { mm_handle * mm_new_nan(const idx_t window, idx_t min_count) { mm_handle *mm = malloc(sizeof(mm_handle)); + if (mm == NULL) return NULL; mm->nodes = malloc(2 * window * sizeof(mm_node*)); mm->node_data = malloc(window * sizeof(mm_node)); + if (mm->nodes == NULL || mm->node_data == NULL) { + free(mm->node_data); + free(mm->nodes); + free(mm); + return NULL; + } mm->s_heap = mm->nodes; mm->l_heap = &mm->nodes[window / 2 + window % 2];