Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion bottleneck/src/move_median/move_median.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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];
Expand Down