From 35a3cfd51ed0069ec80e39d9011b5c097122fe94 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Tue, 2 May 2023 19:34:13 +0000 Subject: [PATCH] examples/nvme: fix reconnect memory leaks 1) In submit_single_io(), if an I/O fails to submit, we need to free the associated task structure, otherwise it gets leaked. 2) When draining I/O, just always check_io() instead of only doing it when current_queue_depth > 0. This is the simplest of ensuring that we cleanup the ns_ctx (including freeing the IO qpairs and the qpair pointer array) if the current_queue_depth is already 0 when starting to drain. Fixes issue #2995. Signed-off-by: Jim Harris Change-Id: I53f336c6a11ff63782dc81c087a58feca0e8a5d7 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/17873 Tested-by: SPDK CI Jenkins Community-CI: Mellanox Build Bot Reviewed-by: Aleksey Marchuk Reviewed-by: Shuhei Matsumoto Reviewed-by: Konrad Sztyber --- examples/nvme/reconnect/reconnect.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/nvme/reconnect/reconnect.c b/examples/nvme/reconnect/reconnect.c index ddfd9d837..a55f74dc6 100644 --- a/examples/nvme/reconnect/reconnect.c +++ b/examples/nvme/reconnect/reconnect.c @@ -411,6 +411,8 @@ submit_single_io(struct perf_task *task) if (spdk_unlikely(rc != 0)) { fprintf(stderr, "starting I/O failed\n"); + spdk_dma_free(task->iov.iov_base); + free(task); } else { ns_ctx->current_queue_depth++; } @@ -537,13 +539,11 @@ work_fn(void *arg) ns_ctx->is_draining = true; } - if (ns_ctx->current_queue_depth > 0) { - check_io(ns_ctx); - if (ns_ctx->current_queue_depth == 0) { - nvme_cleanup_ns_worker_ctx(ns_ctx); - } else { - unfinished_ns_ctx++; - } + check_io(ns_ctx); + if (ns_ctx->current_queue_depth == 0) { + nvme_cleanup_ns_worker_ctx(ns_ctx); + } else { + unfinished_ns_ctx++; } } } while (unfinished_ns_ctx > 0);