Skip to content

Commit 4532540

Browse files
committed
Fix memory leak with LUT function
1 parent a96a69c commit 4532540

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/expr.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,9 @@ double _lut_common_callback(expr_t *expr, int argc, double *args, uint8 interpol
773773
qsort(points, length, sizeof(double) * 2, compare_double);
774774

775775
if (x < points[0]) {
776-
return points[1];
776+
double result = points[1];
777+
free(points);
778+
return result;
777779
}
778780

779781
for (uint32 i = 0; i < length - 1; i++) {
@@ -786,6 +788,9 @@ double _lut_common_callback(expr_t *expr, int argc, double *args, uint8 interpol
786788
continue;
787789
}
788790

791+
free(points);
792+
points = NULL;
793+
789794
if (interpolation == LUT_INTERPOLATION_CLOSEST) {
790795
if (x - x1 < x2 - x) {
791796
return y1;
@@ -803,6 +808,7 @@ double _lut_common_callback(expr_t *expr, int argc, double *args, uint8 interpol
803808
}
804809
}
805810

811+
free(points);
806812
return points[2 * length - 1];
807813
}
808814

0 commit comments

Comments
 (0)