hw/nvme: fix memory leak in fdp ruhid parsing
authorKlaus Jensen <k.jensen@samsung.com>
Tue, 11 Apr 2023 18:34:11 +0000 (20:34 +0200)
committerKlaus Jensen <k.jensen@samsung.com>
Wed, 12 Apr 2023 10:03:02 +0000 (12:03 +0200)
Coverity reports a memory leak of memory when parsing ruhids at
namespace initialization. Since this is just working memory, not needed
beyond the scope of the functions, fix this by adding a g_autofree
annotation.

Reported-by: Coverity (CID 1507979)
Fixes: 73064edfb864 ("hw/nvme: flexible data placement emulation")
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
hw/nvme/ns.c

index cfac960dcf39c4982810a6eb0a36d28913e88360..547c0b154312278b7bcca9efc0faccfae658e78b 100644 (file)
@@ -399,7 +399,8 @@ static bool nvme_ns_init_fdp(NvmeNamespace *ns, Error **errp)
     NvmeEnduranceGroup *endgrp = ns->endgrp;
     NvmeRuHandle *ruh;
     uint8_t lbafi = NVME_ID_NS_FLBAS_INDEX(ns->id_ns.flbas);
-    unsigned int *ruhid, *ruhids;
+    g_autofree unsigned int *ruhids = NULL;
+    unsigned int *ruhid;
     char *r, *p, *token;
     uint16_t *ph;