opal: Fix get locking range info memory leak
Previously, get locking range info will allocate memory everytime. Thus calling this function multiple times will cause memory leak. Now, we allocate only if it is NULL. If it is not, then we just memset to zero. Change-Id: If048416a2056176f86206a33e2b5db210288fe4f Signed-off-by: Chunyang Hui <chunyang.hui@intel.com> Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/472112 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
This commit is contained in:
parent
ac4949807b
commit
5f42a71745
@ -1612,15 +1612,20 @@ opal_get_locking_range_info(struct spdk_opal_dev *dev,
|
||||
return err;
|
||||
}
|
||||
|
||||
info = calloc(1, sizeof(struct spdk_opal_locking_range_info));
|
||||
if (info == NULL) {
|
||||
SPDK_ERRLOG("Memory allocation failed for spdk_opal_locking_range_info\n");
|
||||
return -ENOMEM;
|
||||
if (dev->locking_range_info[locking_range_id] == NULL) {
|
||||
info = calloc(1, sizeof(struct spdk_opal_locking_range_info));
|
||||
if (info == NULL) {
|
||||
SPDK_ERRLOG("Memory allocation failed for spdk_opal_locking_range_info\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
info->locking_range_id = locking_range_id;
|
||||
dev->locking_range_info[locking_range_id] = info;
|
||||
} else {
|
||||
info = dev->locking_range_info[locking_range_id];
|
||||
memset(info, 0, sizeof(*info));
|
||||
info->locking_range_id = locking_range_id;
|
||||
}
|
||||
|
||||
info->locking_range_id = locking_range_id;
|
||||
dev->locking_range_info[locking_range_id] = info;
|
||||
|
||||
opal_clear_cmd(dev);
|
||||
opal_set_comid(dev, dev->comid);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user