[CRIU] [PATCH 10/14] criu/img-remote.c: use xmalloc

Kir Kolyshkin kir at openvz.org
Tue Mar 21 15:03:08 PDT 2017


1. Use xmalloc() where possible.

2. There is no need to print an error message, as xmalloc()
   has already printed it for you.

Cc: Rodrigo Bruno <rbruno at gsd.inesc-id.pt>
Signed-off-by: Kir Kolyshkin <kir at openvz.org>
---
 criu/img-remote.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/criu/img-remote.c b/criu/img-remote.c
index c53217f..1e37bf3 100644
--- a/criu/img-remote.c
+++ b/criu/img-remote.c
@@ -33,12 +33,11 @@ struct snapshot {
 
 struct snapshot *new_snapshot(char *snapshot_id)
 {
-	struct snapshot *s = malloc(sizeof(struct snapshot));
+	struct snapshot *s = xmalloc(sizeof(struct snapshot));
 
-	if (!s) {
-		pr_perror("Failed to allocate snapshot structure");
+	if (!s)
 		return NULL;
-	}
+
 	strncpy(s->snapshot_id, snapshot_id, PATHLEN - 1);
 	s->snapshot_id[PATHLEN - 1]= '\0';
 	return s;
@@ -180,7 +179,6 @@ static int pull_snapshot_ids(void)
 
 		s = new_snapshot(ls->snapshot_id);
 		if (!s) {
-			pr_perror("Unable create new snapshot structure");
 			close(sockfd);
 			return -1;
 		}
@@ -206,7 +204,6 @@ int push_snapshot_id(void)
 
 	rn.snapshot_id = xmalloc(sizeof(char) * PATHLEN);
 	if (!rn.snapshot_id) {
-		pr_perror("Unable to allocate snapshot id buffer");
 		close(sockfd);
 		return -1;
 	}
-- 
2.9.3



More information about the CRIU mailing list