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 <nmanthey@amazon.de>
Reviewed-by: Thomas Friebel <friebelt@amazon.de>
Reviewed-by: Julien Grall <jgrall@amazon.co.uk>
Reviewed-by: Juergen Gross <jgross@suse.com>
/* 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;
}