From a1aa88b7dcac2b22d74908f9276d5d145d8e65a0 Mon Sep 17 00:00:00 2001 From: Yuval Shaia Date: Wed, 16 Jan 2019 17:15:38 +0200 Subject: hw/rdma: Verify that ptr is not NULL before freeing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To cover the case where fini() was called even when init() fails make sure objects are not NULL before calling to non-null-safe destructors. Signed-off-by: Yuval Shaia Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20190116151538.14088-1-yuval.shaia@oracle.com> Signed-off-by: Marcel Apfelbaum --- hw/rdma/rdma_rm.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'hw/rdma/rdma_rm.c') diff --git a/hw/rdma/rdma_rm.c b/hw/rdma/rdma_rm.c index f5b1295890..8bf241e91f 100644 --- a/hw/rdma/rdma_rm.c +++ b/hw/rdma/rdma_rm.c @@ -41,6 +41,9 @@ static inline void res_tbl_init(const char *name, RdmaRmResTbl *tbl, static inline void res_tbl_free(RdmaRmResTbl *tbl) { + if (!tbl->bitmap) { + return; + } qemu_mutex_destroy(&tbl->lock); g_free(tbl->tbl); g_free(tbl->bitmap); @@ -655,5 +658,7 @@ void rdma_rm_fini(RdmaDeviceResources *dev_res, RdmaBackendDev *backend_dev, res_tbl_free(&dev_res->cq_tbl); res_tbl_free(&dev_res->pd_tbl); - g_hash_table_destroy(dev_res->qp_hash); + if (dev_res->qp_hash) { + g_hash_table_destroy(dev_res->qp_hash); + } } -- cgit 1.4.1