OSDN Git Service

hw/block/nvme: fix resource leak in nvme_dif_rw
authorKlaus Jensen <k.jensen@samsung.com>
Mon, 22 Mar 2021 05:58:38 +0000 (06:58 +0100)
committerKlaus Jensen <k.jensen@samsung.com>
Mon, 29 Mar 2021 16:46:47 +0000 (18:46 +0200)
If nvme_map_dptr() fails, nvme_dif_rw() will leak the bounce context.
Fix this by using the same error handling as everywhere else in the
function.

Reported-by: Coverity (CID 1451080)
Fixes: 146f720c5563 ("hw/block/nvme: end-to-end data protection")
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
Reviewed-by: Gollu Appalanaidu <anaidu.gollu@samsung.com>
hw/block/nvme-dif.c

index 2038d72..e6f04fa 100644 (file)
@@ -432,7 +432,7 @@ uint16_t nvme_dif_rw(NvmeCtrl *n, NvmeRequest *req)
 
     status = nvme_map_dptr(n, &req->sg, mapped_len, &req->cmd);
     if (status) {
-        return status;
+        goto err;
     }
 
     ctx->data.bounce = g_malloc(len);