From c18d377c9fd5dc578893cef1e2e8574b150b0169 Mon Sep 17 00:00:00 2001 From: xie xingguo Date: Tue, 15 Jan 2019 16:23:26 +0800 Subject: [PATCH] crush: fix memory leak If we remove the last item of bucket, there should still be one final entry in the __weights__ field of __weight_set__. Free the corresponding memory before we __null__ the pointer. Signed-off-by: xie xingguo --- src/crush/CrushWrapper.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index 0fda4ee89d4..7a323ca0390 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -2440,6 +2440,7 @@ int CrushWrapper::bucket_remove_item(crush_bucket *bucket, int item) weight_set->weights = (__u32*)realloc(weight_set->weights, new_size * sizeof(__u32)); } else { + free(weight_set->weights); weight_set->weights = NULL; } weight_set->size = new_size; @@ -2451,6 +2452,7 @@ int CrushWrapper::bucket_remove_item(crush_bucket *bucket, int item) if (new_size) { arg->ids = (__s32 *)realloc(arg->ids, new_size * sizeof(__s32)); } else { + free(arg->ids); arg->ids = NULL; } arg->ids_size = new_size;