[Ocfs2-tools-devel] [PATCH] fsck.ocfs2: the members of 'o2fsck_state' need to be freed at the end of main()
piaojun
piaojun at huawei.com
Sat Sep 24 01:47:29 PDT 2016
Hi Joseph Qi,
On 2016-9-24 11:25, Joseph Qi wrote:
> Hi Jun,
> _ost is global static variable, so we have no need to free ost itself,
> which pointing _ost.
> For ost members, take ost_dir_inodes for example, we have to use
> ocfs2_bitmap_free to free its allocated space, but not ocfs2_free.
>
Thanks for reviewing, I will fix this problem in [PATCH v2].
> On 2016/9/23 21:06, piaojun wrote:
>> The allocation for the members of 'o2fsck_state' by o2fsck_state_init()
>> need to be freed at last in case of memory leak.
>>
>> Signed-off-by: Jun Piao <piaojun at huawei.com>
>> ---
>> fsck.ocfs2/fsck.c | 14 +++++++++++++-
>> fsck.ocfs2/pass1.c | 1 +
>> 2 files changed, 14 insertions(+), 1 deletion(-)
>>
>> diff --git a/fsck.ocfs2/fsck.c b/fsck.ocfs2/fsck.c
>> index dc5209d..5648b66 100644
>> --- a/fsck.ocfs2/fsck.c
>> +++ b/fsck.ocfs2/fsck.c
>> @@ -232,6 +232,16 @@ errcode_t o2fsck_state_reinit(ocfs2_filesys *fs, o2fsck_state *ost)
>> return 0;
>> }
>>
>> +static void o2fsck_state_release(o2fsck_state *ost)
>> +{
>> + ocfs2_free(&ost->ost_dir_inodes);
>> + ocfs2_free(&ost->ost_reg_inodes);
>> + ocfs2_free(&ost->ost_allocated_clusters);
>> + ocfs2_free(&ost->ost_duplicate_clusters);
>> + ocfs2_free(&ost->ost_icount_in_inodes);
>> + ocfs2_free(&ost->ost_icount_refs);
>> +}
>> +
>> static errcode_t check_superblock(o2fsck_state *ost)
>> {
>> struct ocfs2_dinode *di = ost->ost_fs->fs_super;
>> @@ -1102,7 +1112,9 @@ close:
>> com_err(whoami, ret, "while closing file \"%s\"", filename);
>> /* XXX I wonder about this error.. */
>> fsck_mask |= FSCK_ERROR;
>> - }
>> + }
>> +
>> + o2fsck_state_release(ost);
>>
>> out:
>> return fsck_mask;
>> diff --git a/fsck.ocfs2/pass1.c b/fsck.ocfs2/pass1.c
>> index c076e28..530bd8d 100644
>> --- a/fsck.ocfs2/pass1.c
>> +++ b/fsck.ocfs2/pass1.c
>> @@ -83,6 +83,7 @@ void o2fsck_free_inode_allocs(o2fsck_state *ost)
>>
>> for (i = 0; i < OCFS2_RAW_SB(ost->ost_fs->fs_super)->s_max_slots; i++)
>> ocfs2_free_cached_inode(ost->ost_fs, ost->ost_inode_allocs[i]);
>> + ocfs2_free(&ost->ost_inode_allocs);
>> }
>>
>> /* update our in memory images of the inode chain alloc bitmaps. these
>>
>
>
>
> .
>
More information about the Ocfs2-tools-devel
mailing list