rtsold: fix memory leak in script execution

Since commit 04e9edb544, rtsold has leaked the memory for the
argument vector of every script it runs.

Reported by:	Coverity
Reviewed by:	markj
Fixes:		04e9edb544
MFC after:	1 week
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D34355
This commit is contained in:
Eric van Gyzen 2022-02-23 10:49:12 -06:00
parent a2a8efb4f6
commit 331b84b5db

View File

@ -162,7 +162,7 @@ script_command(const char *cmd, const nvlist_t *limits, nvlist_t *nvlin,
const char *const *iargv, *const *scripts;
char **argv;
size_t argc, i, nscripts;
int fd, status;
int error, fd, status;
if (strcmp(cmd, "script_wait") == 0) {
/* Wait for the result of a previous "script_run" command. */
@ -198,8 +198,10 @@ script_command(const char *cmd, const nvlist_t *limits, nvlist_t *nvlin,
memcpy(argv, iargv, sizeof(*argv) * argc);
fd = script_run(argv);
error = errno;
free(argv);
if (fd < 0)
return (errno);
return (error);
(void)caph_rights_limit(fd, cap_rights_init(&rights, CAP_WRITE));
nvlist_move_descriptor(nvlout, "fd", fd);