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