[CRIU] [PATCH] criu: fix leaks detected by coverity scan

Andrew Vagin avagin at virtuozzo.com
Tue Feb 6 04:42:09 MSK 2018


Applied, thanks!
On Thu, Feb 01, 2018 at 07:04:09PM +0300, Pavel Tikhomirov wrote:
> 1) fix sfle memory leak on get_fle_for_scm error
> 2) fix gfd open descriptor leak on get_fle_for_scm error
> 3-6) fix buf memory leak on read and pwrite errors
> 
> Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
> ---
>  criu/files-reg.c | 7 +++++--
>  criu/sk-unix.c   | 1 +
>  2 files changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/criu/files-reg.c b/criu/files-reg.c
> index 2402f9340..235285893 100644
> --- a/criu/files-reg.c
> +++ b/criu/files-reg.c
> @@ -166,10 +166,12 @@ static int copy_chunk_from_file(int fd, int img, off_t off, size_t len)
>  			ret = pread(fd, buf, min_t(size_t, BUFSIZE, len), off);
>  			if (ret <= 0) {
>  				pr_perror("Can't read from ghost file");
> +				xfree(buf);
>  				return -1;
>  			}
>  			if (write(img, buf, ret) != ret) {
>  				pr_perror("Can't write to image");
> +				xfree(buf);
>  				return -1;
>  			}
>  			off += ret;
> @@ -185,7 +187,6 @@ static int copy_chunk_from_file(int fd, int img, off_t off, size_t len)
>  	}
>  
>  	xfree(buf);
> -
>  	return 0;
>  }
>  
> @@ -245,10 +246,12 @@ static int copy_chunk_to_file(int img, int fd, off_t off, size_t len)
>  			ret = read(img, buf, min_t(size_t, BUFSIZE, len));
>  			if (ret <= 0) {
>  				pr_perror("Can't read from image");
> +				xfree(buf);
>  				return -1;
>  			}
>  			if (pwrite(fd, buf, ret, off) != ret) {
>  				pr_perror("Can't write to file");
> +				xfree(buf);
>  				return -1;
>  			}
>  		} else {
> @@ -268,7 +271,6 @@ static int copy_chunk_to_file(int img, int fd, off_t off, size_t len)
>  	}
>  
>  	xfree(buf);
> -
>  	return 0;
>  }
>  
> @@ -305,6 +307,7 @@ static int mkreg_ghost(char *path, GhostFileEntry *gfe, struct cr_img *img)
>  	if (gfe->chunks) {
>  		if (!gfe->has_size) {
>  			pr_err("Corrupted ghost image -> no size\n");
> +			close(gfd);
>  			return -1;
>  		}
>  
> diff --git a/criu/sk-unix.c b/criu/sk-unix.c
> index 3963a4ad5..0c1d97929 100644
> --- a/criu/sk-unix.c
> +++ b/criu/sk-unix.c
> @@ -939,6 +939,7 @@ int unix_note_scm_rights(int id_for, uint32_t *file_ids, int *fds, int n_ids)
>  		sfle->fle = get_fle_for_scm(tgt, owner);
>  		if (!sfle->fle) {
>  			pr_err("Can't request new fle for scm\n");
> +			xfree(sfle);
>  			return -1;
>  		}
>  
> -- 
> 2.14.3
> 


More information about the CRIU mailing list