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

Submitted by Cyrill Gorcunov on July 5, 2019, 3:38 p.m.

Details

Message ID 20190705153811.22652-13-gorcunov@gmail.com
State Accepted
Series "mem: Cleanup and fixups"
Headers show

Commit Message

Cyrill Gorcunov July 5, 2019, 3:38 p.m.
To shrink code a bit.

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

Patch hide | download patch | download mbox

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;

Comments

Mike Rapoport July 8, 2019, 5:07 p.m.
On Fri, Jul 05, 2019 at 06:38:07PM +0300, Cyrill Gorcunov wrote:
> To shrink code a bit.
> 
> Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>

Reviewed-by: Mike Rapoport <rppt@linux.ibm.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
> 
> _______________________________________________
> CRIU mailing list
> CRIU@openvz.org
> https://lists.openvz.org/mailman/listinfo/criu