From ae845f007976cc3bb503016bc6da80ab3a3f6703 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Thu, 23 Mar 2017 15:02:07 -0700 Subject: [PATCH] criu/img-remote.c: use xmalloc 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 Signed-off-by: Kir Kolyshkin Signed-off-by: Andrei Vagin --- 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 c53217f0f..1e37bf33d 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; }