Blob Blame History Raw
From d26e316c3ffd4658b25f14ea1c42384f251c96de Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
Date: Thu, 13 Jun 2013 16:11:30 +0200
Subject: [PATCH] Close FILE handles on error

Functions for reading quota specification in quotaops.c create new
temporary FILE stream handle, they close it on successful return,
but they forget to close it on unsuccessful return. That leads to
memory leaks. This patch ensures that the handle gets closed in all
cases.
---
 quotaops.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/quotaops.c b/quotaops.c
index 175a945..47ef9a7 100644
--- a/quotaops.c
+++ b/quotaops.c
@@ -334,42 +334,49 @@ int readprivs(struct dquot *qlist, int infd)
 
 		if (cnt != 7) {
 			errstr(_("Bad format:\n%s\n"), line);
+			fclose(fd);
 			return -1;
 		}
 		error = str2space(blocksstring, &blocks);
 		if (error) {
 			errstr(_("Bad block usage: %s: %s\n"),
 				blocksstring, error);
+			fclose(fd);
 			return -1;
 		}
 		error = str2space(bsoftstring, &bsoft);
 		if (error) {
 			errstr(_("Bad block soft limit: %s: %s\n"),
 				bsoftstring, error);
+			fclose(fd);
 			return -1;
 		}
 		error = str2space(bhardstring, &bhard);
 		if (error) {
 			errstr(_("Bad block hard limit: %s: %s\n"),
 				bhardstring, error);
+			fclose(fd);
 			return -1;
 		}
 		error = str2number(inodesstring, &inodes);
 		if (error) {
 			errstr(_("Bad inode usage: %s: %s\n"),
 				inodesstring, error);
+			fclose(fd);
 			return -1;
 		}
 		error = str2number(isoftstring, &isoft);
 		if (error) {
 			errstr(_("Bad inode soft limit: %s: %s\n"),
 				isoftstring, error);
+			fclose(fd);
 			return -1;
 		}
 		error = str2number(ihardstring, &ihard);
 		if (error) {
 			errstr(_("Bad inode hard limit: %s: %s\n"),
 				ihardstring, error);
+			fclose(fd);
 			return -1;
 		}
 
@@ -478,6 +485,7 @@ int readindividualtimes(struct dquot *qlist, int infd)
 		if (cnt != 3) {
 format_err:
 			errstr(_("bad format:\n%s\n"), line);
+			fclose(fd);
 			return -1;
 		}
 		if (!strcmp(btimestr, _("unset")))
@@ -488,6 +496,7 @@ format_err:
 			if (str2timeunits(btime, bunits, &bseconds) < 0) {
 units_err:
 				errstr(_("Bad time units. Units are 'second', 'minute', 'hour', and 'day'.\n"));
+				fclose(fd);
 				return -1;
 			}
 			bseconds += now;
@@ -576,11 +585,13 @@ int readtimes(struct quota_handle **handles, int infd)
 		cnt = sscanf(line, "%s %d %s %d %s", fsp, &btime, bunits, &itime, iunits);
 		if (cnt != 5) {
 			errstr(_("bad format:\n%s\n"), line);
+			fclose(fd);
 			return -1;
 		}
 		if (str2timeunits(btime, bunits, &bseconds) < 0 ||
 		    str2timeunits(itime, iunits, &iseconds) < 0) {
 			errstr(_("Bad time units. Units are 'second', 'minute', 'hour', and 'day'.\n"));
+			fclose(fd);
 			return -1;
 		}
 		for (i = 0; handles[i]; i++) {
-- 
1.8.1.4