[CRIU] [PATCH] util: don't leak cr-img objects

Pavel Emelyanov xemul at parallels.com
Thu Nov 19 05:49:19 PST 2015


On 11/19/2015 03:33 PM, Andrew Vagin wrote:
> On Thu, Nov 19, 2015 at 03:14:39PM +0300, Pavel Emelyanov wrote:
>> On 11/18/2015 10:54 AM, Andrey Vagin wrote:
>>> From: Andrew Vagin <avagin at virtuozzo.com>
>>
>> Some details would be nice. Where does it leak img?
> 
> close_image() should be called for empty images.
> 
>>
>>> Signed-off-by: Andrew Vagin <avagin at virtuozzo.com>
>>> diff --git a/net.c b/net.c
>>> index bfdebad..45c8318 100644
>>> --- a/net.c
>>> +++ b/net.c
>>> @@ -726,16 +726,17 @@ err_free:
>>>  
>>>  static int restore_ip_dump(int type, int pid, char *cmd)
>>>  {
>>> -	int ret = -1;
>>> +	int ret = 0;
>>>  	struct cr_img *img;
>>>  
>>>  	img = open_image(type, O_RSTR, pid);
>>> -	if (empty_image(img))
>>> -		return 0;
>>> -	if (img) {
>>> +	if (img == NULL)
>>> +		return -1;
>>
>> There's no need in this check here, both close_image and empty_image
>> check fro it being null.
> 
> we need to call close_image() if empty_image(img) is true

OK, this counts as "need more details" response ;)
But the if (img == NULL) above is still not required :)

>>
>>> +
>>> +	if (!empty_image(img))
>>>  		ret = run_ip_tool(cmd, "restore", NULL, img_raw_fd(img), -1, 0);
>>> -		close_image(img);
>>> -	}
>>> +
>>> +	close_image(img);
>>>  
>>>  	return ret;
>>>  }
>>>
>>
> .
> 



More information about the CRIU mailing list