2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-31 06:15:24 +00:00

criu: fix leaks detected by coverity scan

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@virtuozzo.com>
This commit is contained in:
Pavel Tikhomirov
2018-02-01 19:04:09 +03:00
committed by Andrei Vagin
parent 6a3878e529
commit c79bef860a
2 changed files with 6 additions and 2 deletions

View File

@@ -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); ret = pread(fd, buf, min_t(size_t, BUFSIZE, len), off);
if (ret <= 0) { if (ret <= 0) {
pr_perror("Can't read from ghost file"); pr_perror("Can't read from ghost file");
xfree(buf);
return -1; return -1;
} }
if (write(img, buf, ret) != ret) { if (write(img, buf, ret) != ret) {
pr_perror("Can't write to image"); pr_perror("Can't write to image");
xfree(buf);
return -1; return -1;
} }
off += ret; off += ret;
@@ -185,7 +187,6 @@ static int copy_chunk_from_file(int fd, int img, off_t off, size_t len)
} }
xfree(buf); xfree(buf);
return 0; 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)); ret = read(img, buf, min_t(size_t, BUFSIZE, len));
if (ret <= 0) { if (ret <= 0) {
pr_perror("Can't read from image"); pr_perror("Can't read from image");
xfree(buf);
return -1; return -1;
} }
if (pwrite(fd, buf, ret, off) != ret) { if (pwrite(fd, buf, ret, off) != ret) {
pr_perror("Can't write to file"); pr_perror("Can't write to file");
xfree(buf);
return -1; return -1;
} }
} else { } else {
@@ -268,7 +271,6 @@ static int copy_chunk_to_file(int img, int fd, off_t off, size_t len)
} }
xfree(buf); xfree(buf);
return 0; return 0;
} }
@@ -305,6 +307,7 @@ static int mkreg_ghost(char *path, GhostFileEntry *gfe, struct cr_img *img)
if (gfe->chunks) { if (gfe->chunks) {
if (!gfe->has_size) { if (!gfe->has_size) {
pr_err("Corrupted ghost image -> no size\n"); pr_err("Corrupted ghost image -> no size\n");
close(gfd);
return -1; return -1;
} }

View File

@@ -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); sfle->fle = get_fle_for_scm(tgt, owner);
if (!sfle->fle) { if (!sfle->fle) {
pr_err("Can't request new fle for scm\n"); pr_err("Can't request new fle for scm\n");
xfree(sfle);
return -1; return -1;
} }