summaryrefslogtreecommitdiffstats
path: root/libmount/src/tab_update.c
diff options
context:
space:
mode:
authorKarel Zak2012-01-30 23:38:18 +0100
committerKarel Zak2012-01-30 23:38:18 +0100
commit801401447beced649cdb032b3c1c3adba6899c38 (patch)
treeb3f9a4160d514f5783a9b3a556246610c973e04a /libmount/src/tab_update.c
parentlibmount: fix resource leak [coverity scan] (diff)
downloadkernel-qcow2-util-linux-801401447beced649cdb032b3c1c3adba6899c38.tar.gz
kernel-qcow2-util-linux-801401447beced649cdb032b3c1c3adba6899c38.tar.xz
kernel-qcow2-util-linux-801401447beced649cdb032b3c1c3adba6899c38.zip
libmount: fix resource leak [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src/tab_update.c')
-rw-r--r--libmount/src/tab_update.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/libmount/src/tab_update.c b/libmount/src/tab_update.c
index a9be364f9..7238faf68 100644
--- a/libmount/src/tab_update.c
+++ b/libmount/src/tab_update.c
@@ -517,7 +517,6 @@ static int update_table(struct libmnt_update *upd, struct libmnt_table *tb)
struct stat st;
struct libmnt_iter itr;
struct libmnt_fs *fs;
- int fd;
mnt_reset_iter(&itr, MNT_ITER_FORWARD);
while(mnt_table_next_fs(tb, &itr, &fs) == 0) {
@@ -538,7 +537,6 @@ static int update_table(struct libmnt_update *upd, struct libmnt_table *tb)
goto leave;
}
- fd = fileno(f);
rc = fchmod(fd, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) ? -errno : 0;
if (!rc && stat(upd->filename, &st) == 0)
@@ -546,6 +544,7 @@ static int update_table(struct libmnt_update *upd, struct libmnt_table *tb)
rc = fchown(fd, st.st_uid, st.st_gid) ? -errno : 0;
fclose(f);
+ f = NULL;
rc = rename(uq, upd->filename) ? -errno : 0;
} else {
rc = -errno;
@@ -553,6 +552,9 @@ static int update_table(struct libmnt_update *upd, struct libmnt_table *tb)
}
leave:
+ if (f)
+ fclose(f);
+
unlink(uq); /* be paranoid */
free(uq);
return rc;