From: Karel Zak Date: Mon, 30 Jan 2012 22:38:18 +0000 (+0100) Subject: libmount: fix resource leak [coverity scan] X-Git-Tag: v2.21-rc2~73 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=801401447beced649cdb032b3c1c3adba6899c38;p=thirdparty%2Futil-linux.git libmount: fix resource leak [coverity scan] Signed-off-by: Karel Zak --- diff --git a/libmount/src/tab_update.c b/libmount/src/tab_update.c index a9be364f91..7238faf687 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;