Fix memory leak in calculateMedian

This commit is contained in:
Frederik Beimgraben 2025-01-13 02:58:08 +01:00
parent 6eb4ec2a22
commit 73ff58d6d3

View File

@ -715,13 +715,17 @@ double calculateMedian(double *pdIn, int iLen) {
// Sort the array using stdlib's qsort function
qsort(pdInSorted, iLen, sizeof(double), compareDoubles);
double median;
if (iLen % 2 == 0) {
return (pdInSorted[iLen/2 - 1] + pdInSorted[iLen/2]) / 2;
median = (pdInSorted[iLen/2 - 1] + pdInSorted[iLen/2]) / 2;
} else {
return pdInSorted[iLen/2];
median = pdInSorted[iLen/2];
}
free(pdInSorted);
return median;
}
/*