]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
fabrics: do not leak nvme_ctrl_t object on connect
authorDaniel Wagner <dwagner@suse.de>
Thu, 1 Aug 2024 13:08:06 +0000 (15:08 +0200)
committerDaniel Wagner <wagi@monom.org>
Thu, 1 Aug 2024 13:33:16 +0000 (15:33 +0200)
valgrinds reports that the nvme_ctrl_t is leaked in the connect command.
Let's introduced a new cleanup helper for this.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
fabrics.c
util/cleanup.h

index 1adaa8099fc55e0921642a81c8a6ed0078012051..438604ac7ae4d1d9585ebe88584aca71c48d180c 100644 (file)
--- a/fabrics.c
+++ b/fabrics.c
@@ -899,7 +899,7 @@ int nvmf_connect(const char *desc, int argc, char **argv)
        unsigned int verbose = 0;
        _cleanup_nvme_root_ nvme_root_t r = NULL;
        nvme_host_t h;
-       nvme_ctrl_t c;
+       _cleanup_nvme_ctrl_ nvme_ctrl_t c = NULL;
        int ret;
        nvme_print_flags_t flags;
        struct nvme_fabrics_config cfg = { 0 };
index f2acde0d3d5378520f4d585d0adf267f29014d5d..ff26cda3e99b22080b3c27891a8e92638586425d 100644 (file)
@@ -42,6 +42,9 @@ static inline void cleanup_nvme_root(nvme_root_t *r)
 }
 #define _cleanup_nvme_root_ __cleanup__(cleanup_nvme_root)
 
+static inline DEFINE_CLEANUP_FUNC(cleanup_nvme_ctrl, nvme_ctrl_t, nvme_free_ctrl)
+#define _cleanup_nvme_ctrl_ __cleanup__(cleanup_nvme_ctrl)
+
 static inline void free_uri(struct nvme_fabrics_uri **uri)
 {
        if (*uri)