cluster: RHEL57 - gfs2_edit: Fix memory leak in savemeta option

Bob Peterson rpeterso at fedoraproject.org
Wed Feb 2 21:15:52 UTC 2011


Gitweb:        http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=ff658f227fa956f1f8e68d37ae49579960358cbd
Commit:        ff658f227fa956f1f8e68d37ae49579960358cbd
Parent:        45b63600a8cc8836f48f580192ced51d0e2f3f7b
Author:        Bob Peterson <rpeterso at redhat.com>
AuthorDate:    Mon Dec 13 10:58:28 2010 -0600
Committer:     Bob Peterson <rpeterso at redhat.com>
CommitterDate: Wed Feb 2 14:36:09 2011 -0600

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#656371
---
 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 fbc1f4f..7c28ae9 100644
--- a/gfs2/edit/savemeta.c
+++ b/gfs2/edit/savemeta.c
@@ -46,7 +46,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 */
@@ -212,6 +211,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' "
@@ -230,8 +230,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) {
@@ -246,6 +248,7 @@ static int save_block(int fd, int out_fd, uint64_t blk)
 	do_write(out_fd, savedata->buf, outsz);
 	total_out += sizeof(savedata->blk) + sizeof(savedata->siglen) + outsz;
 	blks_saved++;
+	brelse(savebh);
 	return blktype;
 }
 


More information about the cluster-commits mailing list