You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
libreport/SOURCES/0020-lib-dump_dir-Clean-up-...

78 lines
1.8 KiB

From 69c83b933da2ac7c4a1450c5882027030eb79022 Mon Sep 17 00:00:00 2001
From: Ernestas Kulik <ekulik@redhat.com>
Date: Tue, 12 Mar 2019 13:30:12 +0100
Subject: [PATCH] lib: dump_dir: Clean up on failure in dd_delete()
All callers assume that dd_delete() will succeed and the dump directory
struct will be freed, but in some cases that does not happen and leaks
occur.
Resolves rhbz#1671233
Signed-off-by: Ernestas Kulik <ekulik@redhat.com>
---
src/lib/dump_dir.c | 26 +++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)
diff --git a/src/lib/dump_dir.c b/src/lib/dump_dir.c
index 632a01fa..4533f4c1 100644
--- a/src/lib/dump_dir.c
+++ b/src/lib/dump_dir.c
@@ -1555,19 +1555,33 @@ static int dd_delete_meta_data(struct dump_dir *dd)
int dd_delete(struct dump_dir *dd)
{
+ int retval;
+
+ retval = 0;
+
if (!dd->locked)
{
error_msg("unlocked problem directory %s cannot be deleted", dd->dd_dirname);
- return -1;
+
+ retval = -1;
+
+ goto close;
}
if (dd_delete_meta_data(dd) != 0)
- return -2;
+ {
+ retval = -2;
+
+ goto close;
+ }
if (delete_file_dir(dd->dd_fd, /*skip_lock_file:*/ true) != 0)
{
perror_msg("Can't remove contents of directory '%s'", dd->dd_dirname);
- return -2;
+
+ retval = -2;
+
+ goto close;
}
unsigned cnt = RMDIR_FAIL_COUNT;
@@ -1586,12 +1600,14 @@ int dd_delete(struct dump_dir *dd)
if (cnt == 0)
{
perror_msg("Can't remove directory '%s'", dd->dd_dirname);
- return -3;
+
+ retval = -3;
}
dd->locked = 0; /* delete_file_dir already removed .lock */
+close:
dd_close(dd);
- return 0;
+ return retval;
}
int dd_chown(struct dump_dir *dd, uid_t new_uid)
--
2.21.0