render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From 357fc40405c4967654972ecdf0b210fed885185d Mon Sep 17 00:00:00 2001
Message-Id: <357fc40405c4967654972ecdf0b210fed885185d@dist-git>
From: Michal Privoznik <mprivozn@redhat.com>
Date: Fri, 19 Mar 2021 11:51:58 +0100
Subject: [PATCH] RHEL: virdevmapper: Don't leak DIR on OOM in
 virDMSanitizepath()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This is a RHEL only patch, because it fixes a small issue in one
of backported commits that was basically rewritten from scratch
(v4.5.0-400-g6bf725c07c).

During the rewrite I've introduced a problem, in which opened
/dev/mapper/ directory can leak if OOM happened afterwards.

Fixes: 6bf725c07c25b56937c494b6c7e83e6ca27ec54c
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1933557
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Message-Id: <c3ba31ab36478ea466128572aa53498555c7995f.1616151101.git.mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/util/virdevmapper.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/util/virdevmapper.c b/src/util/virdevmapper.c
index dcb3c08df5..33cde6ca0c 100644
--- a/src/util/virdevmapper.c
+++ b/src/util/virdevmapper.c
@@ -216,7 +216,7 @@ virDMSanitizepath(const char *path)
         VIR_AUTOFREE(char *) tmp = NULL;
 
         if (virAsprintf(&tmp, DEV_DM_DIR "/%s", ent->d_name) < 0)
-            return NULL;
+            goto cleanup;
 
         if (stat(tmp, &sb[1]) == 0 &&
             sb[0].st_rdev == sb[1].st_rdev) {
@@ -225,6 +225,7 @@ virDMSanitizepath(const char *path)
         }
     }
 
+ cleanup:
     virDirClose(&dh);
     return ret;
 }
-- 
2.31.0