summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Zeleny <jzeleny@redhat.com>2011-11-04 04:11:03 -0400
committerStephen Gallagher <sgallagh@redhat.com>2011-11-07 08:57:17 -0500
commit5a66e8f96603b34497de8fed762a9ac41e929efa (patch)
tree70bb08f96664c91f15abfecdae9ea089f67dabd8
parent21386a358f0850b660139fe6db2bdd2e14c8a4ef (diff)
downloadsssd-5a66e8f96603b34497de8fed762a9ac41e929efa.tar.gz
sssd-5a66e8f96603b34497de8fed762a9ac41e929efa.tar.bz2
sssd-5a66e8f96603b34497de8fed762a9ac41e929efa.zip
Fixed possible resource leak in create_mail_spool()
https://fedorahosted.org/sssd/ticket/1071
-rw-r--r--src/tools/tools_util.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/tools/tools_util.c b/src/tools/tools_util.c
index fb4c4ef7..7dfdecf8 100644
--- a/src/tools/tools_util.c
+++ b/src/tools/tools_util.c
@@ -408,7 +408,7 @@ int create_mail_spool(TALLOC_CTX *mem_ctx,
uid_t uid, gid_t gid)
{
char *spool_file = NULL;
- int fd;
+ int fd = -1;
int ret;
spool_file = talloc_asprintf(mem_ctx, "%s/%s", maildir, username);
@@ -448,18 +448,18 @@ int create_mail_spool(TALLOC_CTX *mem_ctx,
ret = errno;
DEBUG(1, ("Cannot fsync() the spool file: [%d][%s]\n",
ret, strerror(ret)));
- goto fail;
}
- ret = close(fd);
- if (ret != 0) {
- ret = errno;
- DEBUG(1, ("Cannot close() the spool file: [%d][%s]\n",
- ret, strerror(ret)));
- goto fail;
+fail:
+ if (fd >= 0) {
+ ret = close(fd);
+ if (ret != 0) {
+ ret = errno;
+ DEBUG(1, ("Cannot close() the spool file: [%d][%s]\n",
+ ret, strerror(ret)));
+ }
}
-fail:
reset_selinux_file_context();
talloc_free(spool_file);
return ret;