From patchwork Fri Dec 6 09:57:51 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zheng Liu X-Patchwork-Id: 297665 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 A66B62C0098 for ; Fri, 6 Dec 2013 20:55:40 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757570Ab3LFJzj (ORCPT ); Fri, 6 Dec 2013 04:55:39 -0500 Received: from mail-pd0-f178.google.com ([209.85.192.178]:55662 "EHLO mail-pd0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757235Ab3LFJzd (ORCPT ); Fri, 6 Dec 2013 04:55:33 -0500 Received: by mail-pd0-f178.google.com with SMTP id y10so745155pdj.23 for ; Fri, 06 Dec 2013 01:55:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dPo+891e0+p1F2YbCePWWLjdTojVRUpvS+g5eSphG68=; b=oRZr0dqrXFDm6/hAnOS/F8z3/zo86pNWSA9KbTthzab5m9tPmyzaU8TmXLuHDmwexb hKsWaJjlrlj7QQwJ8zqGlIR3x6inGaV4QCPMlIIHB/y4pmBSVeaf0CGsYVUbrucaMNFe sXcQ0IZFKicuG4VS4uHDBKWA5JWaJjEHxrPtOUuLgybRP1bMTvw/eMHgT5vHSDsfjxE6 CsxSExm2zQG7BudRzIMWfJLTmBcJ3qExqcQHVzL41LkH/Jq4Q0cu5wS/GCbOD6O3OBGW dfMoHRazz+ME8jgCWqdh+sigZi3KdhOKOCxwUf3+J1aQKwCXN3Fiyd4wP/9r8hQZj8+F DcFQ== X-Received: by 10.68.129.99 with SMTP id nv3mr3107191pbb.40.1386323731890; Fri, 06 Dec 2013 01:55:31 -0800 (PST) Received: from alpha.taobao.ali.com ([182.92.247.2]) by mx.google.com with ESMTPSA id m2sm56582620pbn.19.2013.12.06.01.55.29 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 06 Dec 2013 01:55:31 -0800 (PST) From: Zheng Liu To: linux-ext4@vger.kernel.org Cc: Theodore Ts'o , "Darrick J. Wong" , Zheng Liu Subject: [PATCH v3 04/30] libext2fs: fix memory leaks in extended attribute code Date: Fri, 6 Dec 2013 17:57:51 +0800 Message-Id: <1386323897-2354-5-git-send-email-wenqing.lz@taobao.com> X-Mailer: git-send-email 1.7.9.7 In-Reply-To: <1386323897-2354-1-git-send-email-wenqing.lz@taobao.com> References: <1386323897-2354-1-git-send-email-wenqing.lz@taobao.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: "Darrick J. Wong" Fix some memory leaks and data disclosure problems in the extended attribute writing code. Signed-off-by: Darrick J. Wong --- lib/ext2fs/ext_attr.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/ext2fs/ext_attr.c b/lib/ext2fs/ext_attr.c index f7d623a..a8a8c93 100644 --- a/lib/ext2fs/ext_attr.c +++ b/lib/ext2fs/ext_attr.c @@ -364,7 +364,7 @@ static errcode_t prep_ea_block_for_write(ext2_filsys fs, ext2_ino_t ino, /* Single-user block. We're done here. */ if (header->h_refcount == 1) - return 0; + goto out2; /* We need to CoW the block. */ header->h_refcount--; @@ -384,10 +384,11 @@ static errcode_t prep_ea_block_for_write(ext2_filsys fs, ext2_ino_t ino, goal = ext2fs_inode_table_loc(fs, grp); err = ext2fs_alloc_block2(fs, goal, NULL, &blk); if (err) - return err; + goto out2; ext2fs_file_acl_block_set(fs, (struct ext2_inode *)inode, blk); out2: - ext2fs_free_mem(&block_buf); + if (block_buf) + ext2fs_free_mem(&block_buf); out: return err; } @@ -509,7 +510,7 @@ errcode_t ext2fs_xattrs_write(struct ext2_xattr_handle *handle) write_ea_block: /* Write the EA block */ - err = ext2fs_get_mem(handle->fs->blocksize, &block_buf); + err = ext2fs_get_memzero(handle->fs->blocksize, &block_buf); if (err) goto out;