summaryrefslogtreecommitdiffstats
path: root/src
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:46 -0400
commitee5d8931739ad453f9c669b252f5e3bf1e1d4c0a (patch)
tree0e5f5f7e5877d0272be1b2f769e088a14bd01489 /src
parentc7a825ba91b8285b87e19688e5f5f3241f1a67bf (diff)
downloadsssd-ee5d8931739ad453f9c669b252f5e3bf1e1d4c0a.tar.gz
sssd-ee5d8931739ad453f9c669b252f5e3bf1e1d4c0a.tar.xz
sssd-ee5d8931739ad453f9c669b252f5e3bf1e1d4c0a.zip
Fix potential resource leak in remove_tree_with_ctx()
https://fedorahosted.org/sssd/ticket/515
Diffstat (limited to 'src')
-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;
}