diff options
author | Theodore Ts'o <tytso@mit.edu> | 2014-05-10 17:29:18 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2014-05-13 10:12:57 -0400 |
commit | 4af2b156ffa2d50ebfc9207e667d18d5a7a1ae45 (patch) | |
tree | cf2448f5e6d739323e6f1418f1203166a9f25ccb | |
parent | 68ba77caa72aa91eb9473e624657c16cda8c361d (diff) | |
download | e2fsprogs-4af2b156ffa2d50ebfc9207e667d18d5a7a1ae45.tar.gz |
quota: fix memory leak in quota_compare_and_update()
The quota_handle wasn't getting closed in quota_compare_and_update().
Fix this, and also make sure that quota_file_close() doesn't
unnecessarily modify the quota inode if it's not necessary. Otherwise
e2fsck will claim that the file system is modified when it didn't need
to be.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Reviewed-by: Aditya Kali <adityakali@google.com>
-rw-r--r-- | lib/quota/mkquota.c | 9 | ||||
-rw-r--r-- | lib/quota/quotaio.c | 9 |
2 files changed, 15 insertions, 3 deletions
diff --git a/lib/quota/mkquota.c b/lib/quota/mkquota.c index f5ae0e00..ed10890a 100644 --- a/lib/quota/mkquota.c +++ b/lib/quota/mkquota.c @@ -597,7 +597,7 @@ errcode_t quota_compare_and_update(quota_ctx_t qctx, int qtype, err = qh.qh_ops->scan_dquots(&qh, scan_dquots_callback, &scan_data); if (err) { log_err("Error scanning dquots"); - goto out; + goto out_close_qh; } for (n = dict_first(dict); n; n = dict_next(dict, n)) { @@ -612,6 +612,13 @@ errcode_t quota_compare_and_update(quota_ctx_t qctx, int qtype, } *usage_inconsistent = scan_data.usage_is_inconsistent; +out_close_qh: + err = quota_file_close(&qh); + if (err) { + log_err("Cannot close quotafile: %s", error_message(errno)); + if (qh.qh_qf.e2_file) + ext2fs_file_close(qh.qh_qf.e2_file); + } out: return err; } diff --git a/lib/quota/quotaio.c b/lib/quota/quotaio.c index 7e98ed75..a95a1f9e 100644 --- a/lib/quota/quotaio.c +++ b/lib/quota/quotaio.c @@ -356,9 +356,14 @@ errcode_t quota_file_close(struct quota_handle *h) if (h->qh_ops->end_io && h->qh_ops->end_io(h) < 0) return -1; if (h->qh_qf.e2_file) { + __u64 new_size, size; + + new_size = compute_inode_size(h->qh_qf.fs, h->qh_qf.ino); ext2fs_file_flush(h->qh_qf.e2_file); - ext2fs_file_set_size2(h->qh_qf.e2_file, - compute_inode_size(h->qh_qf.fs, h->qh_qf.ino)); + if (ext2fs_file_get_lsize(h->qh_qf.e2_file, &size)) + new_size = 0; + if (size != new_size) + ext2fs_file_set_size2(h->qh_qf.e2_file, new_size); ext2fs_file_close(h->qh_qf.e2_file); } |