[Ocfs2-tools-devel] [PATCH 0/8] Fix some memory leak problems in ocfs2-tools-1.8.4

piaojun piaojun at huawei.com
Sun Mar 29 01:06:29 PDT 2015


I have checked all the eight patches with checkpatch.pl so that the
whitespace errors are all fixed and there are no obvious style problems
now. Moreover, according to your suggestion free() is replaced with
ocfs2_free(). But in [patch 3/8] free() is still called in order to fit in
the code in the context.

在 2015/3/28 5:34, Mark Fasheh 写道:
> On Wed, Mar 18, 2015 at 03:35:41PM +0800, piaojun wrote:
>> When I was reviewing the code of ocfs2-tools-1.8.4, some memory leak
>> problems were found. The summarization of the problems are listed below:
>>
>> Signed-off-by: Jun Piao <piaojun at huawei.com>
>> Reviewed-by: Alex Chen <alex.chen at huawei.com>
>>
>> [PATCH 1/8] Fix the memory leak problem in journal.c
>> [PATCH 2/8] Fix the memory leak problem in freefs.c
>> [PATCH 3/8] Fix the memory leak problem in mount.ocfs2.c
>> [PATCH 4/8] Fix the memory leak problem in ocfs2_hb_ctl.c
>> [PATCH 5/8] Fix the memory leak problem in tunefs.ocfs2
>> [PATCH 6/8] Fix the memory leak problem in mkfs.c
>> [PATCH 7/8] Fix the memory leak problem in o2image.c
>> [PATCH 8/8] Fix the memory leak problem in image.c
> 
> 
> Btw, these patches had a lot of whitespace errors. I programmed git to fix
> them for me but in general we want to avoid things like spaces at the
> start/end of lines and spaces before tabs. Attached is the patch of what git
> did so you have a better idea of what we want to avoid.
> 	--Mark
> 
> diff --git a/fsck.ocfs2/journal.c b/fsck.ocfs2/journal.c
> index 31557b7..cec867a 100644
> --- a/fsck.ocfs2/journal.c
> +++ b/fsck.ocfs2/journal.c
> @@ -928,7 +928,7 @@ static errcode_t check_journal_walk(o2fsck_state *ost,
>  		if (ci) {
>  			ocfs2_free_cached_inode(fs, ci);
>  			ci = NULL;
> -		}								
> +		}
>  	}
>  
>  	if (ci)
> diff --git a/libocfs2/freefs.c b/libocfs2/freefs.c
> index 1fa9424..d7615c5 100644
> --- a/libocfs2/freefs.c
> +++ b/libocfs2/freefs.c
> @@ -48,7 +48,7 @@ void ocfs2_free_fs_inode_allocs(ocfs2_filesys *fs)
>  		}
>  	}
>  
> - 	if (fs->fs_eb_allocs) {
> +	if (fs->fs_eb_allocs) {
>  		for (i = 0; i < max_slots; i++) {
>  			ocfs2_free_cached_inode(fs, fs->fs_eb_allocs[i]);
>  		}
> diff --git a/mkfs.ocfs2/mkfs.c b/mkfs.ocfs2/mkfs.c
> index cf088f4..9717e0e 100644
> --- a/mkfs.ocfs2/mkfs.c
> +++ b/mkfs.ocfs2/mkfs.c
> @@ -1241,32 +1241,32 @@ free_state(State *s)
>  {
>  	if(!s)
>  		return;
> -	
> +
>  	if (s->vol_label) {
>  		free(s->vol_label);
>  		s->vol_label = NULL;
>  	}
> -	
> +
>  	if (s->device_name) {
>  		free(s->device_name);
>  		s->device_name = NULL;
>  	}
> -	
> +
>  	if (s->cluster_stack) {
>  		free(s->cluster_stack);
>  		s->cluster_stack = NULL;
>  	}
> -	
> +
>  	if (s->cluster_name) {
>  		free(s->cluster_name);
>  		s->cluster_name = NULL;
>  	}
> -	
> +
>  	if (s->global_bm) {
>  		free_global_bitmap(s, s->global_bm);
>  		s->global_bm = NULL;
>  	}
> -	
> +
>  	if (s->system_group) {
>  		free_alloc_group(s->system_group);
>  		s->system_group = NULL;
> @@ -1902,8 +1902,8 @@ free_alloc_group(AllocGroup *group)
>  		free(group->gd);
>  		group->gd = NULL;
>  	}
> -	
> -	if (group->name) {	
> +
> +	if (group->name) {
>  		free(group->name);
>  		group->name = NULL;
>  	}
> @@ -2023,21 +2023,21 @@ free_global_bitmap(State *s, AllocBitmap *global_bm)
>  
>  	if (!global_bm)
>  		return;
> -		
> +
>  	if (global_bm->name) {
>  		free(global_bm->name);
> -		global_bm->name = NULL;		
> +		global_bm->name = NULL;
>  	}
>  
>  	if (global_bm->groups) {
> -	
> -		for(i = 0; i < s->nr_cluster_groups; i++)		
> +
> +		for(i = 0; i < s->nr_cluster_groups; i++)
>  			free_alloc_group(global_bm->groups[i]);
>  
> -		free(global_bm->groups);	
> +		free(global_bm->groups);
>  		global_bm->groups = NULL;
>  	}
> -	
> +
>  	free(global_bm);
>  	global_bm = NULL;
>  	return;
> @@ -2233,10 +2233,10 @@ free_directory(DirData *dir)
>  	if (dir) {
>  		if (dir->buf) {
>  			free(dir->buf);
> -			dir->buf = NULL;	
> +			dir->buf = NULL;
>  		}
>  		free(dir);
> -		dir = NULL;		
> +		dir = NULL;
>  	}
>  
>  	return;
> @@ -2949,15 +2949,15 @@ static void
>  free_records(SystemFileDiskRecord *record[])
>  {
>  	int i;
> -	
> -	if (!record)	
> +
> +	if (!record)
>  		return;
> -	
> -	for (i = 0; i < NUM_SYSTEM_INODES; i++) {	
> +
> +	for (i = 0; i < NUM_SYSTEM_INODES; i++) {
>  		if (record[i]) {
>  			free(record[i]);
>  			record[i] = NULL;
> -		}	
> +		}
>  	}
>  	return;
>  }
> 
> 
> --
> Mark Fasheh
> 
> .
> 




More information about the Ocfs2-tools-devel mailing list