gfs2-utils: RHEL7 - fsck.gfs2: Fix memory leaks in pass1_process_rgrp
Andrew Price
andyp at fedoraproject.org
Tue Apr 7 21:24:05 UTC 2015
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=03a7bea1ace2ab3b8bd753662b6b848027a6e9b8
Commit: 03a7bea1ace2ab3b8bd753662b6b848027a6e9b8
Parent: d496c725c7566620a587b8d10afe607f0e7e7454
Author: Andrew Price <anprice at redhat.com>
AuthorDate: Fri Feb 20 13:26:08 2015 +0000
Committer: Andrew Price <anprice at redhat.com>
CommitterDate: Wed Apr 1 16:51:35 2015 +0100
fsck.gfs2: Fix memory leaks in pass1_process_rgrp
Spotted by coverity: "Variable ibuf going out of scope leaks the storage
it points to"
Signed-off-by: Andrew Price <anprice at redhat.com>
---
gfs2/fsck/pass1.c | 14 +++++++++-----
1 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/gfs2/fsck/pass1.c b/gfs2/fsck/pass1.c
index b516a21..69c88f4 100644
--- a/gfs2/fsck/pass1.c
+++ b/gfs2/fsck/pass1.c
@@ -1625,7 +1625,10 @@ static int pass1_process_rgrp(struct gfs2_sbd *sdp, struct rgrp_tree *rgd)
{
unsigned k, n, i;
uint64_t *ibuf = malloc(sdp->bsize * GFS2_NBBY * sizeof(uint64_t));
- int ret;
+ int ret = 0;
+
+ if (ibuf == NULL)
+ return FSCK_ERROR;
for (k = 0; k < rgd->ri.ri_length; k++) {
n = lgfs2_bm_scan(rgd, k, ibuf, GFS2_BLKST_DINODE);
@@ -1633,11 +1636,11 @@ static int pass1_process_rgrp(struct gfs2_sbd *sdp, struct rgrp_tree *rgd)
if (n) {
ret = pass1_process_bitmap(sdp, rgd, ibuf, n);
if (ret)
- return ret;
+ goto out;
}
if (fsck_abort)
- return 0;
+ goto out;
/*
For GFS1, we have to count the "free meta" blocks in the
resource group and mark them specially so we can count them
@@ -1650,12 +1653,13 @@ static int pass1_process_rgrp(struct gfs2_sbd *sdp, struct rgrp_tree *rgd)
for (i = 0; i < n; i++) {
gfs2_blockmap_set(bl, ibuf[i], GFS2_BLKST_UNLINKED);
if (fsck_abort)
- return 0;
+ goto out;
}
}
+out:
free(ibuf);
- return 0;
+ return ret;
}
/**
More information about the cluster-commits
mailing list