[CRIU] [PATCH] fix many unclosed file opened by open_image_ro

Andrew Vagin avagin at parallels.com
Wed Oct 24 08:48:42 EDT 2012


On Wed, Oct 24, 2012 at 01:13:12PM +0400, Huang Qiang wrote:
> Many image files opened by open_image_ro weren't closed before return, fix
> them all in this patch.
> 
> Signed-off-by: Huang Qiang <h.huangqiang at huawei.com>
> ---

Acked-by: Andrew Vagin <avagin at parallels.com>

One comment is inline.

Thanks.

> @@ -867,7 +879,8 @@ static int prepare_ipc_var(int pid)
>  	ret = pb_read_one(fd, &var, PB_IPCNS_VAR);
>  	if (ret <= 0) {
>  		pr_err("Failed to read IPC namespace variables\n");
> -		return -EFAULT;
> +		ret = -EFAULT;
> +		goto err;
>  	}
> 
>  	ipc_sysctl_req(var, CTL_PRINT);
> @@ -877,9 +890,13 @@ static int prepare_ipc_var(int pid)
> 
>  	if (ret < 0) {
>  		pr_err("Failed to prepare IPC namespace variables\n");
> -		return -EFAULT;
> +		ret = -EFAULT;
> +		goto err;
>  	}
>  	return close_safe(&fd);
> +err:
> +	close_safe(&fd);
> +	return ret;


I think the next variant is better:
        ret = pb_read_one(fd, &var, PB_IPCNS_VAR);
+	close_safe(&fd)
        if (ret <= 0) {
		pr_err("Failed to read IPC namespace variables\n");
...
-	return close_safe(&fd);
+	return 0;

FYI: close_safe may change errno.

This patch contains a few such places, you could fix them incrementally.

>  }
> 
>  int prepare_ipc_ns(int pid)


More information about the CRIU mailing list