From patchwork Sun May 11 04:32:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Theodore Ts'o X-Patchwork-Id: 347755 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 4F32D14008A for ; Sun, 11 May 2014 14:33:19 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754668AbaEKEdR (ORCPT ); Sun, 11 May 2014 00:33:17 -0400 Received: from imap.thunk.org ([74.207.234.97]:60797 "EHLO imap.thunk.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753935AbaEKEdJ (ORCPT ); Sun, 11 May 2014 00:33:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=thunk.org; s=ef5046eb; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=yRt17l9+Y54W3EIESSgooXMZxT4Sb+y7hyoIKfcyjH8=; b=HA6Ie8GgqyPdF2xMeq/xTJUENJsUQs9vjrIZW9p5OuGrJ2fK6sWIZFkUA9EeUIc12XupxLSIEx3DPzxJYG2q6C9jYpmGqAQYQUyUjKOC+FXVF+KlEpvfa/SMBjnZHqim/YgR2b7zY6R/qcvRS5L6X2eBFIbcPzgiNnosM6bd0os=; Received: from root (helo=closure.thunk.org) by imap.thunk.org with local-esmtp (Exim 4.80) (envelope-from ) id 1WjLRf-0001aE-TX; Sun, 11 May 2014 04:33:03 +0000 Received: by closure.thunk.org (Postfix, from userid 15806) id 407A058089B; Sun, 11 May 2014 00:33:03 -0400 (EDT) From: Theodore Ts'o To: Ext4 Developers List Cc: adityakali@google.com, Theodore Ts'o Subject: [PATCH 4/9] quota: fix memory leak in quota_compare_and_update() Date: Sun, 11 May 2014 00:32:48 -0400 Message-Id: <1399782773-20029-5-git-send-email-tytso@mit.edu> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1399782773-20029-1-git-send-email-tytso@mit.edu> References: <1399782773-20029-1-git-send-email-tytso@mit.edu> X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: tytso@thunk.org X-SA-Exim-Scanned: No (on imap.thunk.org); SAEximRunCond expanded to false Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org 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" Cc: adityakali@google.com Reviewed-by: Aditya Kali --- lib/quota/mkquota.c | 9 ++++++++- 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 f5ae0e0..ed10890 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 7e98ed7..a95a1f9 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); }