Fix memory leak in calculateMedian
This commit is contained in:
parent
6eb4ec2a22
commit
73ff58d6d3
@ -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;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Loading…
Reference in New Issue
Block a user