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