Skip to content

Commit 82e9809

Browse files
authored
fix froll memory leaks (#7300)
1 parent 251e88d commit 82e9809

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/froll.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,7 @@ void frollmaxExact(const double *x, uint64_t nx, ans_t *ans, int k, double fill,
681681
ans->dbl_v[i] = w;
682682
}
683683
}
684+
free(isnan);
684685
}
685686
}
686687

@@ -841,7 +842,6 @@ void frollminExact(const double *x, uint64_t nx, ans_t *ans, int k, double fill,
841842
bool *isnan = malloc(sizeof(*isnan) * nx); // isnan lookup - we use it to reduce ISNAN calls in nested loop
842843
if (!isnan) { // # nocov start
843844
ansSetMsg(ans, 3, "%s: Unable to allocate memory for isnan", __func__); // raise error
844-
free(isnan);
845845
return;
846846
} // # nocov end
847847
bool truehasnf = hasnf>0;
@@ -885,6 +885,7 @@ void frollminExact(const double *x, uint64_t nx, ans_t *ans, int k, double fill,
885885
ans->dbl_v[i] = w;
886886
}
887887
}
888+
free(isnan);
888889
}
889890
}
890891

src/frolladaptive.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ void frolladaptivemaxExact(const double *x, uint64_t nx, ans_t *ans, const int *
554554
}
555555
}
556556
}
557+
free(isnan);
557558
}
558559
}
559560

@@ -581,7 +582,6 @@ void frolladaptiveminExact(const double *x, uint64_t nx, ans_t *ans, const int *
581582
bool *isnan = malloc(sizeof(*isnan) * nx); // isnan lookup - we use it to reduce ISNAN calls in nested loop
582583
if (!isnan) { // # nocov start
583584
ansSetMsg(ans, 3, "%s: Unable to allocate memory for isnan", __func__); // raise error
584-
free(isnan);
585585
return;
586586
} // # nocov end
587587
bool truehasnf = hasnf>0;
@@ -633,6 +633,7 @@ void frolladaptiveminExact(const double *x, uint64_t nx, ans_t *ans, const int *
633633
}
634634
}
635635
}
636+
free(isnan);
636637
}
637638
}
638639

@@ -647,7 +648,6 @@ void frolladaptiveprodFast(const double *x, uint64_t nx, ans_t *ans, const int *
647648
double *cs = malloc(sizeof(*cs) * nx);
648649
if (!cs) { // # nocov start
649650
ansSetMsg(ans, 3, "%s: Unable to allocate memory for cumprod", __func__); // raise error
650-
free(cs);
651651
return;
652652
} // # nocov end
653653
if (!truehasnf) {
@@ -679,19 +679,19 @@ void frolladaptiveprodFast(const double *x, uint64_t nx, ans_t *ans, const int *
679679
uint64_t *cn = malloc(sizeof(*cn) * nx); // cumulative NA counter, used the same way as cumprod, same as uint64_t cn[nx] but no segfault
680680
if (!cn) { // # nocov start
681681
ansSetMsg(ans, 3, "%s: Unable to allocate memory for cum NA counter", __func__); // raise error
682-
free(cs); free(cn);
682+
free(cs);
683683
return;
684684
} // # nocov end
685685
uint64_t *cpinf = malloc(sizeof(*cpinf) * nx);
686686
if (!cpinf) { // # nocov start
687687
ansSetMsg(ans, 3, "%s: Unable to allocate memory for cum Inf counter", __func__); // raise error
688-
free(cs); free(cn); free(cpinf);
688+
free(cs); free(cn);
689689
return;
690690
} // # nocov end
691691
uint64_t *cninf = malloc(sizeof(*cninf) * nx);
692692
if (!cninf) { // # nocov start
693693
ansSetMsg(ans, 3, "%s: Unable to allocate memory for cum -Inf counter", __func__); // raise error
694-
free(cs); free(cn); free(cpinf); free(cninf);
694+
free(cs); free(cn); free(cpinf);
695695
return;
696696
} // # nocov end
697697
for (uint64_t i=0; i<nx; i++) { // loop over observations to calculate cumprod and cum NA counter

0 commit comments

Comments
 (0)