[CRIU] [PATCH 1/3] mem: return -1 from __parasite_dump_pages_seized in error cases

Andrei Vagin avagin at virtuozzo.com
Sat Apr 28 09:02:29 MSK 2018


Here is one of often mistakes:

int funcX()
{
	int ret;

	ret = funcA()
	if (ret < 0)
		goto err;

	if (smth)
		goto err; // return 0 !!!!

err:
	return ret;
}

Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 criu/mem.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/criu/mem.c b/criu/mem.c
index b2a3adc9c..dc67fc50d 100644
--- a/criu/mem.c
+++ b/criu/mem.c
@@ -340,7 +340,7 @@ static int __parasite_dump_pages_seized(struct pstree_item *item,
 	struct page_pipe *pp;
 	struct vma_area *vma_area;
 	struct page_xfer xfer = { .parent = NULL };
-	int ret = -1;
+	int ret, exit_code = -1;
 	unsigned cpp_flags = 0;
 	unsigned long pmc_size;
 	int possible_pid_reuse = 0;
@@ -367,7 +367,6 @@ static int __parasite_dump_pages_seized(struct pstree_item *item,
 			 pmc_size * PAGE_SIZE))
 		return -1;
 
-	ret = -1;
 	if (!(mdc->pre_dump || mdc->lazy))
 		/*
 		 * Chunk mode pushes pages portion by portion. This mode
@@ -468,6 +467,9 @@ again:
 	 */
 
 	ret = task_reset_dirty_track(item->pid->real);
+	if (ret)
+		goto out_xfer;
+	exit_code = 0;
 out_xfer:
 	if (!mdc->pre_dump)
 		xfer.close(&xfer);
@@ -479,7 +481,7 @@ out_pp:
 out:
 	pmc_fini(&pmc);
 	pr_info("----------------------------------------\n");
-	return ret;
+	return exit_code;
 }
 
 int parasite_dump_pages_seized(struct pstree_item *item,
-- 
2.14.3



More information about the CRIU mailing list