cmd: Do not leak param in cmd_Parse()

The cmd_Parse() function calls strdup() to create a temporary string
when there is a parameter in the form "-<name>=<value>".  This is
done in order to parse the <name> and <value> components of the
parameter.

This memory is not freed when the last parameter of the command is the
form "-<name>=<value>".  Always free the param pointer at the end of
cmd_Parse() to avoid this memory leak.

This memory leak was found by running the tests/cmd/command-t unit test
program with valgrind.

Change-Id: I85f8f5f10660268596072c8bb8be2c014ac46ad8
Reviewed-on: https://gerrit.openafs.org/15086
Reviewed-by: Mark Vitale <mvitale@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
This commit is contained in:
Michael Meffie 2023-02-22 14:47:55 -05:00
parent de46edef69
commit 983a670b9d

View File

@ -1087,6 +1087,7 @@ cmd_Parse(int argc, char **argv, struct cmd_syndesc **outsyntax)
out:
if (code && ts != NULL)
ResetSyntax(ts);
free(param);
return code;
}