From: Sage Weil Date: Fri, 21 Jul 2017 17:50:31 +0000 (-0400) Subject: crush/CrushWrapper: only allocate weight_set if non-empty X-Git-Tag: v12.1.2~150^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=31b73305b29efa39825b014ae1ba07a2664d6e0b;p=ceph.git crush/CrushWrapper: only allocate weight_set if non-empty Signed-off-by: Sage Weil --- diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index ad57dae1a5e4..c01856607afd 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -2136,15 +2136,17 @@ void CrushWrapper::decode(bufferlist::iterator& blp) assert(bucket_index < arg_map.size); crush_choose_arg *arg = &arg_map.args[bucket_index]; ::decode(arg->weight_set_size, blp); - arg->weight_set = (crush_weight_set*)calloc( - arg->weight_set_size, sizeof(crush_weight_set)); - for (__u32 k = 0; k < arg->weight_set_size; k++) { - crush_weight_set *weight_set = &arg->weight_set[k]; - ::decode(weight_set->size, blp); - weight_set->weights = (__u32*)calloc( - weight_set->size, sizeof(__u32)); - for (__u32 l = 0; l < weight_set->size; l++) - ::decode(weight_set->weights[l], blp); + if (arg->weight_set_size) { + arg->weight_set = (crush_weight_set*)calloc( + arg->weight_set_size, sizeof(crush_weight_set)); + for (__u32 k = 0; k < arg->weight_set_size; k++) { + crush_weight_set *weight_set = &arg->weight_set[k]; + ::decode(weight_set->size, blp); + weight_set->weights = (__u32*)calloc( + weight_set->size, sizeof(__u32)); + for (__u32 l = 0; l < weight_set->size; l++) + ::decode(weight_set->weights[l], blp); + } } ::decode(arg->ids_size, blp); if (arg->ids_size) {