Blame SOURCES/0238-lib-dump_dir-Clean-up-on-failure-in-dd_delete.patch

b12e4c
From e70412faf236002abc42739eef30aaaf9019e702 Mon Sep 17 00:00:00 2001
b12e4c
From: Ernestas Kulik <ekulik@redhat.com>
b12e4c
Date: Mon, 18 Mar 2019 10:22:08 +0100
b12e4c
Subject: [PATCH] lib: dump_dir: Clean up on failure in dd_delete()
b12e4c
b12e4c
All callers assume that dd_delete() will succeed and the dump directory
b12e4c
struct will be freed, but in some cases that does not happen and leaks
b12e4c
occur.
b12e4c
b12e4c
Signed-off-by: Ernestas Kulik <ekulik@redhat.com>
b12e4c
---
b12e4c
 src/lib/dump_dir.c | 20 ++++++++++++++++----
b12e4c
 1 file changed, 16 insertions(+), 4 deletions(-)
b12e4c
b12e4c
diff --git a/src/lib/dump_dir.c b/src/lib/dump_dir.c
b12e4c
index 7e8ee01..eb0c176 100644
b12e4c
--- a/src/lib/dump_dir.c
b12e4c
+++ b/src/lib/dump_dir.c
b12e4c
@@ -963,16 +963,26 @@ static int delete_file_dir(int dir_fd, bool skip_lock_file)
b12e4c
 
b12e4c
 int dd_delete(struct dump_dir *dd)
b12e4c
 {
b12e4c
+    int retval;
b12e4c
+
b12e4c
+    retval = 0;
b12e4c
+
b12e4c
     if (!dd->locked)
b12e4c
     {
b12e4c
         error_msg("unlocked problem directory %s cannot be deleted", dd->dd_dirname);
b12e4c
-        return -1;
b12e4c
+
b12e4c
+        retval = -1;
b12e4c
+
b12e4c
+        goto close;
b12e4c
     }
b12e4c
 
b12e4c
     if (delete_file_dir(dd->dd_fd, /*skip_lock_file:*/ true) != 0)
b12e4c
     {
b12e4c
         perror_msg("Can't remove contents of directory '%s'", dd->dd_dirname);
b12e4c
-        return -2;
b12e4c
+
b12e4c
+        retval = -2;
b12e4c
+
b12e4c
+        goto close;
b12e4c
     }
b12e4c
 
b12e4c
     unsigned cnt = RMDIR_FAIL_COUNT;
b12e4c
@@ -991,12 +1001,14 @@ int dd_delete(struct dump_dir *dd)
b12e4c
     if (cnt == 0)
b12e4c
     {
b12e4c
         perror_msg("Can't remove directory '%s'", dd->dd_dirname);
b12e4c
-        return -3;
b12e4c
+
b12e4c
+        retval = -3;
b12e4c
     }
b12e4c
 
b12e4c
     dd->locked = 0; /* delete_file_dir already removed .lock */
b12e4c
+close:
b12e4c
     dd_close(dd);
b12e4c
-    return 0;
b12e4c
+    return retval;
b12e4c
 }
b12e4c
 
b12e4c
 int dd_chown(struct dump_dir *dd, uid_t new_uid)
b12e4c
-- 
b12e4c
2.21.0
b12e4c