From c162dd0e3843fbf1d75334c69297588842858417 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Thu, 18 Feb 2016 11:02:36 -0700 Subject: [PATCH] nvme_qpair_ut: clean up submitted tracker This fixes a memory leak in the unit test. Change-Id: Ie94459e8e46e966c437ad43702a04f1a8f9becdb Signed-off-by: Daniel Verkamp --- .../lib/nvme/unit/nvme_qpair_c/nvme_qpair_ut.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/test/lib/nvme/unit/nvme_qpair_c/nvme_qpair_ut.c b/test/lib/nvme/unit/nvme_qpair_c/nvme_qpair_ut.c index 35f936ff14..cc4d4105a4 100644 --- a/test/lib/nvme/unit/nvme_qpair_c/nvme_qpair_ut.c +++ b/test/lib/nvme/unit/nvme_qpair_c/nvme_qpair_ut.c @@ -214,8 +214,10 @@ test3(void) { struct nvme_qpair qpair = {}; struct nvme_request *req; + struct nvme_tracker *tr; struct spdk_nvme_ctrlr ctrlr = {}; struct spdk_nvme_registers regs = {}; + uint16_t cid; prepare_submit_request_test(&qpair, &ctrlr, ®s); @@ -228,8 +230,22 @@ test3(void) CU_ASSERT(qpair.sq_tail == 1); + /* + * Since sq_tail was 0 when the command was submitted, it is in cmd[0]. + * Extract its command ID to retrieve its tracker. + */ + cid = qpair.cmd[0].cid; + tr = qpair.act_tr[cid]; + SPDK_CU_ASSERT_FATAL(tr != NULL); + + /* + * Complete the tracker so that it is returned to the free list. + * This also frees the request. + */ + nvme_qpair_manual_complete_tracker(&qpair, tr, SPDK_NVME_SCT_GENERIC, SPDK_NVME_SC_SUCCESS, 0, + false); + cleanup_submit_request_test(&qpair); - nvme_free_request(req); } static void