xfs
[Top] [All Lists]

Re: [PATCH v2] xfsprogs: fix resource leak in longform_dir2_rebuild()

To: Li Zhong <zhong@xxxxxxxxxxxxxxxxxx>
Subject: Re: [PATCH v2] xfsprogs: fix resource leak in longform_dir2_rebuild()
From: Dave Chinner <david@xxxxxxxxxxxxx>
Date: Wed, 16 Oct 2013 08:39:36 +1100
Cc: xfsprogs <xfs@xxxxxxxxxxx>, Chandra Seetharaman <sekharan@xxxxxxxxxx>
Delivered-to: xfs@xxxxxxxxxxx
In-reply-to: <1381805731.3106.5.camel@ThinkPad-T5421>
References: <1381560174.3064.4.camel@ThinkPad-T5421> <20131014214601.GJ5663@dastard> <1381805731.3106.5.camel@ThinkPad-T5421>
User-agent: Mutt/1.5.21 (2010-09-15)
On Tue, Oct 15, 2013 at 10:55:31AM +0800, Li Zhong wrote:
> coverity scan 997010 reported following leak:
> 
> 1309                if (error) {
> 1310                        do_warn(
> 1311        _("space reservation failed (%d), filesystem may be out of 
> space\n"),
> 1312                                error);
>       25. Breaking from loop
> 1313                        break;
> 1314                }
> 
> ......
> 
> 1342                libxfs_trans_commit(tp,
> 1343                                XFS_TRANS_RELEASE_LOG_RES|XFS_TRANS_SYNC);
> 1344        }
> 
> CID 997010 (#1 of 1): Resource leak (RESOURCE_LEAK)
> 26. leaked_storage: Variable "tp" going out of scope leaks the storage it 
> points to.
> 1345}
> 
> Though not reported by coverity, it seems that there might be some entries in
> flist which needs to be freed in the failure case below 
> libxfs_dir_createname(),
> and libxfs_bunmapi().
> 
> The fix cleans up the code by stacking the error handling at the end of the
> function, and jumping to the error handler label for the above cases. (fail
> directly by calling res_failed() for reservation failure.)
> 
> Signed-off-by: Li Zhong <zhong@xxxxxxxxxxxxxxxxxx>

Looks much better. Thanks! :)

Reviewed-by: Dave Chinner <dchinner@xxxxxxxxxx>

-- 
Dave Chinner
david@xxxxxxxxxxxxx

<Prev in Thread] Current Thread [Next in Thread>