From: Klaus Jensen Date: Tue, 11 Apr 2023 18:54:44 +0000 (+0200) Subject: hw/nvme: fix memory leak in nvme_dsm X-Git-Tag: v7.2.2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c22120835295f2bbb7d101f1fa60abb70029be85;p=thirdparty%2Fqemu.git hw/nvme: fix memory leak in nvme_dsm 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é Signed-off-by: Klaus Jensen (cherry picked from commit 4b32319cdacd99be983e1a74128289ef52c5964e) Signed-off-by: Michael Tokarev --- diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index 1d3e0584520..749a6938dd7 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -2491,6 +2491,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; }