From 81809eed6ed9e312f2022b1d33d439da04d89c50 Mon Sep 17 00:00:00 2001 From: Svetlana Shmidt Date: Tue, 8 Sep 2020 11:38:31 +0000 Subject: [PATCH] fix memory leak in subtract function --- src/daemon/distribution.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/daemon/distribution.c b/src/daemon/distribution.c index 51cfeafd1..e73b2afa8 100644 --- a/src/daemon/distribution.c +++ b/src/daemon/distribution.c @@ -417,3 +417,39 @@ int distribution_sub(distribution_t *d1, distribution_t *d2) { free(cmp_status); return 0; } + +/*int distribution_sub(distribution_t *d1, distribution_t *d2) { + if (d1 == NULL || d2 == NULL) { + return errno = EINVAL; + } + + if (d1->num_buckets != d2->num_buckets) { + return errno = EINVAL; + } + + pthread_mutex_lock(&d1->mutex); + pthread_mutex_lock(&d2->mutex); + + if (d1->total_sum < d2->total_sum) { + pthread_mutex_unlock(&d1->mutex); + pthread_mutex_unlock(&d2->mutex); + return ERANGE; + } else { + d1->total_sum -= d2->total_sum; + for (size_t i = 0; i < tree_size(d1->num_buckets); ++i) { + if (d1->tree[i].maximum != d2->tree[i].maximum || + d1->tree[i].bucket_counter < d2->tree[i].bucket_counter) { + pthread_mutex_unlock(&d2->mutex); + pthread_mutex_unlock(&d1->mutex); + return errno = EINVAL; + } + + d1->tree[i].bucket_counter -= d2->tree[i].bucket_counter; + } + } + + pthread_mutex_unlock(&d2->mutex); + pthread_mutex_unlock(&d1->mutex); + + return 0; +}*/ -- 2.47.3