From 3c82906fc34382a442ac8df169b18bcb6b950505 Mon Sep 17 00:00:00 2001 From: Frederik Beimgraben Date: Mon, 13 Jan 2025 02:49:19 +0100 Subject: [PATCH] Fix memory leak --- MMS24-25.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/MMS24-25.c b/MMS24-25.c index 357f019..6f57c77 100644 --- a/MMS24-25.c +++ b/MMS24-25.c @@ -716,10 +716,12 @@ double calculateMedian(double *pdIn, int iLen) { qsort(pdInSorted, iLen, sizeof(double), compareDoubles); if (iLen % 2 == 0) { - return (pdIn[iLen/2 - 1] + pdIn[iLen/2]) / 2; + return (pdInSorted[iLen/2 - 1] + pdInSorted[iLen/2]) / 2; } else { - return pdIn[iLen/2]; + return pdInSorted[iLen/2]; } + + free(pdInSorted); } /*