Commit 66af6221 authored by GangCao's avatar GangCao Committed by Tomasz Zawadzki
Browse files

bdev: check whether memory allocated already

In the case of bdev initialization, the memory could
not be allocated. When cleaning up, it needs to check
whether the memory pointer is valid or not before
touching the address of the pointer.

This is to fix below issue:
https://github.com/spdk/spdk/issues/1126



Change-Id: Iec0e2c5a40ad153a96fb939414a15ac3b9112a01
Signed-off-by: default avatarGangCao <gang.cao@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/478849


Community-CI: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatar <box.b.chen@intel.com>
Reviewed-by: default avataryidong0635 <dongx.yi@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent cbc9d343
Loading
Loading
Loading
Loading
+26 −17
Original line number Diff line number Diff line
@@ -1125,12 +1125,17 @@ bdev_mgr_unregister_cb(void *io_device)
{
	spdk_bdev_fini_cb cb_fn = g_fini_cb_fn;

	if (g_bdev_mgr.bdev_io_pool) {
		if (spdk_mempool_count(g_bdev_mgr.bdev_io_pool) != g_bdev_opts.bdev_io_pool_size) {
			SPDK_ERRLOG("bdev IO pool count is %zu but should be %u\n",
				    spdk_mempool_count(g_bdev_mgr.bdev_io_pool),
				    g_bdev_opts.bdev_io_pool_size);
		}

		spdk_mempool_free(g_bdev_mgr.bdev_io_pool);
	}

	if (g_bdev_mgr.buf_small_pool) {
		if (spdk_mempool_count(g_bdev_mgr.buf_small_pool) != BUF_SMALL_POOL_SIZE) {
			SPDK_ERRLOG("Small buffer pool count is %zu but should be %u\n",
				    spdk_mempool_count(g_bdev_mgr.buf_small_pool),
@@ -1138,6 +1143,10 @@ bdev_mgr_unregister_cb(void *io_device)
			assert(false);
		}

		spdk_mempool_free(g_bdev_mgr.buf_small_pool);
	}

	if (g_bdev_mgr.buf_large_pool) {
		if (spdk_mempool_count(g_bdev_mgr.buf_large_pool) != BUF_LARGE_POOL_SIZE) {
			SPDK_ERRLOG("Large buffer pool count is %zu but should be %u\n",
				    spdk_mempool_count(g_bdev_mgr.buf_large_pool),
@@ -1145,9 +1154,9 @@ bdev_mgr_unregister_cb(void *io_device)
			assert(false);
		}

	spdk_mempool_free(g_bdev_mgr.bdev_io_pool);
	spdk_mempool_free(g_bdev_mgr.buf_small_pool);
		spdk_mempool_free(g_bdev_mgr.buf_large_pool);
	}

	spdk_free(g_bdev_mgr.zero_buffer);

	cb_fn(g_fini_cb_arg);