gfs2-utils: master - gfs2_edit: Fix memory leak in savemeta option

Bob Peterson rpeterso at fedoraproject.org
Thu Oct 14 14:25:55 UTC 2010


Gitweb:        http://git.fedorahosted.org/git/gfs2-utils.git?p=gfs2-utils.git;a=commitdiff;h=8aeb2e4395371b7d978db67edabd24a0fcae6e32
Commit:        8aeb2e4395371b7d978db67edabd24a0fcae6e32
Parent:        fe0a538720649eb5f33c6ee90257cf25ff607f7b
Author:        Bob Peterson <bob at ganesha.(none)>
AuthorDate:    Fri Oct 1 08:30:09 2010 -0500
Committer:     Bob Peterson <rpeterso at redhat.com>
CommitterDate: Thu Oct 14 08:45:36 2010 -0500

gfs2_edit: Fix memory leak in savemeta option

The savemeta option of gfs2_edit was not releasing its buffers
after they were used, so they kept accumulating in memory.
In large file systems, it was nearly impossible to save the metadata
because it would run out of memory and start swapping to disk.

rhbz#634623
---
 gfs2/edit/savemeta.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c
index e31970d..480567c 100644
--- a/gfs2/edit/savemeta.c
+++ b/gfs2/edit/savemeta.c
@@ -35,7 +35,6 @@ struct saved_metablock {
 };
 
 struct saved_metablock *savedata;
-struct gfs2_buffer_head *savebh;
 uint64_t last_fs_block, last_reported_block, blks_saved, total_out, pct;
 uint64_t journal_blocks[MAX_JOURNALS_SAVED];
 uint64_t gfs1_journal_size = 0; /* in blocks */
@@ -200,6 +199,7 @@ static int save_block(int fd, int out_fd, uint64_t blk)
 	int blktype, blklen, outsz;
 	uint16_t trailing0;
 	char *p;
+	struct gfs2_buffer_head *savebh;
 
 	if (blk > last_fs_block) {
 		fprintf(stderr, "\nWarning: bad block pointer '0x%llx' "
@@ -218,8 +218,10 @@ static int save_block(int fd, int out_fd, uint64_t blk)
 	   inode, not the block within the inode "blk". They may or may not
 	   be the same thing. */
 	if (get_gfs_struct_info(savebh, &blktype, &blklen) &&
-	    !block_is_systemfile())
+	    !block_is_systemfile()) {
+		brelse(savebh);
 		return 0; /* Not metadata, and not system file, so skip it */
+	}
 	trailing0 = 0;
 	p = &savedata->buf[blklen - 1];
 	while (*p=='\0' && trailing0 < sbd.bsize) {
@@ -257,6 +259,7 @@ static int save_block(int fd, int out_fd, uint64_t blk)
 	}
 	total_out += sizeof(savedata->blk) + sizeof(savedata->siglen) + outsz;
 	blks_saved++;
+	brelse(savebh);
 	return blktype;
 }
 


More information about the cluster-commits mailing list