bdev/rbd: fix double-free when failing to initialize cluster

When bdev_rados_cluster_init encounters an error, it shuts down the cluster
before returning, but since the pointer is still set, bdev_rbd_free will
attempt to shut it down again, which causes a crash.
Therefore, set the pointer to NULL after the first shutdown to indicate
that the cluster object does not exist anymore.

Change-Id: Ie403471e8aba881cb6380e74bd1a4ca8d67cbc68
Signed-off-by: Lukas Stockner <lstockner@genesiscloud.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/16203
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: Shuhei Matsumoto <smatsumoto@nvidia.com>
This commit is contained in:
Lukas Stockner 2023-01-09 15:45:14 +01:00 committed by Tomasz Zawadzki
parent a5d5ab27d1
commit 3c5a8ddc41

View File

@ -200,6 +200,7 @@ bdev_rados_cluster_init(const char *user_id, const char *const *config,
if (ret < 0) { if (ret < 0) {
SPDK_ERRLOG("Failed to set %s = %s\n", entry[0], entry[1]); SPDK_ERRLOG("Failed to set %s = %s\n", entry[0], entry[1]);
rados_shutdown(*cluster); rados_shutdown(*cluster);
*cluster = NULL;
return -1; return -1;
} }
entry += 2; entry += 2;
@ -209,6 +210,7 @@ bdev_rados_cluster_init(const char *user_id, const char *const *config,
if (ret < 0) { if (ret < 0) {
SPDK_ERRLOG("Failed to read conf file\n"); SPDK_ERRLOG("Failed to read conf file\n");
rados_shutdown(*cluster); rados_shutdown(*cluster);
*cluster = NULL;
return -1; return -1;
} }
} }
@ -217,6 +219,7 @@ bdev_rados_cluster_init(const char *user_id, const char *const *config,
if (ret < 0) { if (ret < 0) {
SPDK_ERRLOG("Failed to connect to rbd_pool\n"); SPDK_ERRLOG("Failed to connect to rbd_pool\n");
rados_shutdown(*cluster); rados_shutdown(*cluster);
*cluster = NULL;
return -1; return -1;
} }