OSDN Git Service

hw/nvme: fix memory leak in nvme_dsm
authorKlaus Jensen <k.jensen@samsung.com>
Tue, 11 Apr 2023 18:54:44 +0000 (20:54 +0200)
committerKlaus Jensen <k.jensen@samsung.com>
Wed, 12 Apr 2023 10:03:09 +0000 (12:03 +0200)
The iocb (and the allocated memory to hold LBA ranges) leaks if reading
the LBA ranges fails.

Fix this by adding a free and an unref of the iocb.

Reported-by: Coverity (CID 1508281)
Fixes: d7d1474fd85d ("hw/nvme: reimplement dsm to allow cancellation")
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
hw/nvme/ctrl.c

index 8b7be14..ac24eeb 100644 (file)
@@ -2619,6 +2619,9 @@ static uint16_t nvme_dsm(NvmeCtrl *n, NvmeRequest *req)
         status = nvme_h2c(n, (uint8_t *)iocb->range, sizeof(NvmeDsmRange) * nr,
                           req);
         if (status) {
+            g_free(iocb->range);
+            qemu_aio_unref(iocb);
+
             return status;
         }