summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Gallagher <sgallagh@redhat.com>2010-06-17 15:55:42 -0400
committerStephen Gallagher <sgallagh@redhat.com>2010-06-17 16:28:51 -0400
commit4c2cf0bc498c59343257fbae6dd93ec1a9fb88bc (patch)
tree570c5191f651bfe5fb677b66fa711a4ccf7a4c53
parent6d65f4d78567cdcab9b0ab52e1f08ad054278cc7 (diff)
downloadsssd-4c2cf0bc498c59343257fbae6dd93ec1a9fb88bc.tar.gz
sssd-4c2cf0bc498c59343257fbae6dd93ec1a9fb88bc.tar.xz
sssd-4c2cf0bc498c59343257fbae6dd93ec1a9fb88bc.zip
Fix potential resource leak in remove_tree_with_ctx()
https://fedorahosted.org/sssd/ticket/515
-rw-r--r--src/tools/files.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/tools/files.c b/src/tools/files.c
index 3d45679d4..694753549 100644
--- a/src/tools/files.c
+++ b/src/tools/files.c
@@ -110,7 +110,7 @@ static int remove_tree_with_ctx(TALLOC_CTX *mem_ctx,
struct dirent direntp;
struct stat statres;
DIR *rootdir = NULL;
- int ret;
+ int ret, err;
rootdir = opendir(root);
if (rootdir == NULL) {
@@ -174,6 +174,7 @@ static int remove_tree_with_ctx(TALLOC_CTX *mem_ctx,
}
ret = closedir(rootdir);
+ rootdir = NULL;
if (ret != 0) {
ret = errno;
goto fail;
@@ -185,7 +186,15 @@ static int remove_tree_with_ctx(TALLOC_CTX *mem_ctx,
goto fail;
}
+ ret = EOK;
+
fail:
+ if (rootdir) { /* clean up on abnormal exit but retain return code */
+ err = closedir(rootdir);
+ if (err) {
+ DEBUG(1, ("closedir failed, bad dirp?\n"));
+ }
+ }
return ret;
}