From: xie xingguo Date: Tue, 15 Jan 2019 08:23:26 +0000 (+0800) Subject: crush: fix memory leak X-Git-Tag: v14.1.0~365^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F25959%2Fhead;p=ceph.git 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 --- diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index 0fda4ee89d40a..7a323ca039034 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;