From: Norbert Manthey Date: Fri, 26 Feb 2021 14:41:38 +0000 (+0100) Subject: xenstore_client: handle memory on error X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=00948dcd6a5412695b42c6d5045b0d3075b14114;p=people%2Fsstabellini%2Fxen-unstable.git%2F.git xenstore_client: handle memory on error In case a command fails, also free the memory. As this is for the CLI client, currently the leaked memory is freed right after receiving the error, as the application terminates next. Similarly, if the allocation fails, do not use the NULL pointer afterwards, but instead error out. This bug was discovered and resolved using Coverity Static Analysis Security Testing (SAST) by Synopsys, Inc. Signed-off-by: Norbert Manthey Reviewed-by: Thomas Friebel Reviewed-by: Julien Grall Reviewed-by: Juergen Gross --- diff --git a/tools/xenstore/xenstore_client.c b/tools/xenstore/xenstore_client.c index 8015bfe5be..ddbafc5175 100644 --- a/tools/xenstore/xenstore_client.c +++ b/tools/xenstore/xenstore_client.c @@ -382,11 +382,14 @@ perform(enum mode mode, int optind, int argc, char **argv, struct xs_handle *xsh /* Copy path, because we can't modify argv because we will need it again if xs_transaction_end gives us EAGAIN. */ char *p = malloc(strlen(path) + 1); + if (!p) + return 1; strcpy(p, path); path = p; again: if (do_rm(path, xsh, xth)) { + free(path); return 1; }