bdev/iscsi: fix memory leaks on connection failures
create_iscsi_lun freed the provided parameters under one condition, and did not under some other. The behavior is now clarified. When create_iscsi_lun succeeded, the parameters are passed to an iscsi bdev and will be freed together with its removal, but if the bdev could not be created, the params need to be freed manually. Change-Id: I010421d48461b365a324488029e11c90a4e20a37 Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com> Reviewed-on: https://review.gerrithub.io/420569 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-by: Ziye Yang <optimistyzy@gmail.com> Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
This commit is contained in:
parent
3d9690a5e5
commit
244c9ab9eb
@ -572,6 +572,16 @@ complete_conn_req(struct bdev_iscsi_conn_req *req, struct spdk_bdev *bdev,
|
||||
{
|
||||
TAILQ_REMOVE(&g_iscsi_conn_req, req, link);
|
||||
req->create_cb(req->create_cb_arg, bdev, status);
|
||||
if (status) {
|
||||
/* if the request failed and no iscsi lun was
|
||||
* created then we could not hand over this
|
||||
* memory and have to free it manually now.
|
||||
*/
|
||||
iscsi_destroy_context(req->context);
|
||||
free(req->initiator_iqn);
|
||||
free(req->bdev_name);
|
||||
free(req->url);
|
||||
}
|
||||
free(req);
|
||||
}
|
||||
|
||||
@ -609,7 +619,9 @@ create_iscsi_lun(struct iscsi_context *context, char *url, char *initiator_iqn,
|
||||
rc = spdk_bdev_register(&lun->bdev);
|
||||
if (rc) {
|
||||
spdk_io_device_unregister(lun, NULL);
|
||||
goto error_return;
|
||||
pthread_mutex_destroy(&lun->mutex);
|
||||
free(lun);
|
||||
return rc;
|
||||
}
|
||||
|
||||
lun->no_master_ch_poller_td = spdk_get_thread();
|
||||
@ -618,10 +630,6 @@ create_iscsi_lun(struct iscsi_context *context, char *url, char *initiator_iqn,
|
||||
|
||||
*bdev = &lun->bdev;
|
||||
return 0;
|
||||
|
||||
error_return:
|
||||
iscsi_free_lun(lun);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static void
|
||||
|
Loading…
x
Reference in New Issue
Block a user