Blame SOURCES/quota-4.01-Close-FILE-handles-on-error.patch

370c56
From d26e316c3ffd4658b25f14ea1c42384f251c96de Mon Sep 17 00:00:00 2001
370c56
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
370c56
Date: Thu, 13 Jun 2013 16:11:30 +0200
370c56
Subject: [PATCH] Close FILE handles on error
370c56
370c56
Functions for reading quota specification in quotaops.c create new
370c56
temporary FILE stream handle, they close it on successful return,
370c56
but they forget to close it on unsuccessful return. That leads to
370c56
memory leaks. This patch ensures that the handle gets closed in all
370c56
cases.
370c56
---
370c56
 quotaops.c | 11 +++++++++++
370c56
 1 file changed, 11 insertions(+)
370c56
370c56
diff --git a/quotaops.c b/quotaops.c
370c56
index 175a945..47ef9a7 100644
370c56
--- a/quotaops.c
370c56
+++ b/quotaops.c
370c56
@@ -334,42 +334,49 @@ int readprivs(struct dquot *qlist, int infd)
370c56
 
370c56
 		if (cnt != 7) {
370c56
 			errstr(_("Bad format:\n%s\n"), line);
370c56
+			fclose(fd);
370c56
 			return -1;
370c56
 		}
370c56
 		error = str2space(blocksstring, &blocks;;
370c56
 		if (error) {
370c56
 			errstr(_("Bad block usage: %s: %s\n"),
370c56
 				blocksstring, error);
370c56
+			fclose(fd);
370c56
 			return -1;
370c56
 		}
370c56
 		error = str2space(bsoftstring, &bsoft);
370c56
 		if (error) {
370c56
 			errstr(_("Bad block soft limit: %s: %s\n"),
370c56
 				bsoftstring, error);
370c56
+			fclose(fd);
370c56
 			return -1;
370c56
 		}
370c56
 		error = str2space(bhardstring, &bhard);
370c56
 		if (error) {
370c56
 			errstr(_("Bad block hard limit: %s: %s\n"),
370c56
 				bhardstring, error);
370c56
+			fclose(fd);
370c56
 			return -1;
370c56
 		}
370c56
 		error = str2number(inodesstring, &inodes);
370c56
 		if (error) {
370c56
 			errstr(_("Bad inode usage: %s: %s\n"),
370c56
 				inodesstring, error);
370c56
+			fclose(fd);
370c56
 			return -1;
370c56
 		}
370c56
 		error = str2number(isoftstring, &isoft);
370c56
 		if (error) {
370c56
 			errstr(_("Bad inode soft limit: %s: %s\n"),
370c56
 				isoftstring, error);
370c56
+			fclose(fd);
370c56
 			return -1;
370c56
 		}
370c56
 		error = str2number(ihardstring, &ihard);
370c56
 		if (error) {
370c56
 			errstr(_("Bad inode hard limit: %s: %s\n"),
370c56
 				ihardstring, error);
370c56
+			fclose(fd);
370c56
 			return -1;
370c56
 		}
370c56
 
370c56
@@ -478,6 +485,7 @@ int readindividualtimes(struct dquot *qlist, int infd)
370c56
 		if (cnt != 3) {
370c56
 format_err:
370c56
 			errstr(_("bad format:\n%s\n"), line);
370c56
+			fclose(fd);
370c56
 			return -1;
370c56
 		}
370c56
 		if (!strcmp(btimestr, _("unset")))
370c56
@@ -488,6 +496,7 @@ format_err:
370c56
 			if (str2timeunits(btime, bunits, &bseconds) < 0) {
370c56
 units_err:
370c56
 				errstr(_("Bad time units. Units are 'second', 'minute', 'hour', and 'day'.\n"));
370c56
+				fclose(fd);
370c56
 				return -1;
370c56
 			}
370c56
 			bseconds += now;
370c56
@@ -576,11 +585,13 @@ int readtimes(struct quota_handle **handles, int infd)
370c56
 		cnt = sscanf(line, "%s %d %s %d %s", fsp, &btime, bunits, &itime, iunits);
370c56
 		if (cnt != 5) {
370c56
 			errstr(_("bad format:\n%s\n"), line);
370c56
+			fclose(fd);
370c56
 			return -1;
370c56
 		}
370c56
 		if (str2timeunits(btime, bunits, &bseconds) < 0 ||
370c56
 		    str2timeunits(itime, iunits, &iseconds) < 0) {
370c56
 			errstr(_("Bad time units. Units are 'second', 'minute', 'hour', and 'day'.\n"));
370c56
+			fclose(fd);
370c56
 			return -1;
370c56
 		}
370c56
 		for (i = 0; handles[i]; i++) {
370c56
-- 
370c56
1.8.1.4
370c56