[CRIU] [PATCH 12/16] mem/page-pipe: Use xrealloc_safe in page_pipe_add_hole

Cyrill Gorcunov gorcunov at gmail.com
Fri Jul 5 18:38:07 MSK 2019


To shrink code a bit.

Signed-off-by: Cyrill Gorcunov <gorcunov at gmail.com>
---
 criu/page-pipe.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/criu/page-pipe.c b/criu/page-pipe.c
index 534380b0f1ce..a8216962dac4 100644
--- a/criu/page-pipe.c
+++ b/criu/page-pipe.c
@@ -298,14 +298,12 @@ int page_pipe_add_hole(struct page_pipe *pp, unsigned long addr,
 		       unsigned int flags)
 {
 	if (pp->free_hole >= pp->nr_holes) {
-		pp->holes = xrealloc(pp->holes,
-				(pp->nr_holes + PP_HOLES_BATCH) * sizeof(struct iovec));
-		if (!pp->holes)
+		size_t new_size = (pp->nr_holes + PP_HOLES_BATCH) * sizeof(struct iovec);
+		if (xrealloc_safe(&pp->holes, new_size))
 			return -1;
 
-		pp->hole_flags = xrealloc(pp->hole_flags,
-					  (pp->nr_holes + PP_HOLES_BATCH) * sizeof(unsigned int));
-		if(!pp->hole_flags)
+		new_size = (pp->nr_holes + PP_HOLES_BATCH) * sizeof(unsigned int);
+		if (xrealloc_safe(&pp->hole_flags, new_size))
 			return -1;
 
 		pp->nr_holes += PP_HOLES_BATCH;
-- 
2.20.1



More information about the CRIU mailing list