log_server_accept: fix memory leak of evlog when logging a sub-command.

Coverity CID 238643
This commit is contained in:
Todd C. Miller
2021-08-14 09:11:02 -06:00
parent 340d753947
commit e2abcd6cb6

View File

@@ -245,7 +245,7 @@ static bool
log_server_accept(char * const command_info[], char * const run_argv[], log_server_accept(char * const command_info[], char * const run_argv[],
char * const run_envp[]) char * const run_envp[])
{ {
struct eventlog *evlog; struct eventlog *evlog = NULL;
struct timespec now; struct timespec now;
bool ret = false; bool ret = false;
debug_decl(log_server_accept, SUDOERS_DEBUG_PLUGIN); debug_decl(log_server_accept, SUDOERS_DEBUG_PLUGIN);
@@ -286,6 +286,7 @@ log_server_accept(char * const command_info[], char * const run_argv[],
} else { } else {
if (!init_log_details(&audit_details, evlog)) if (!init_log_details(&audit_details, evlog))
goto done; goto done;
evlog = NULL;
/* Open connection to log server, send hello and accept messages. */ /* Open connection to log server, send hello and accept messages. */
client_closure = log_server_open(&audit_details, &now, false, client_closure = log_server_open(&audit_details, &now, false,
@@ -295,6 +296,8 @@ log_server_accept(char * const command_info[], char * const run_argv[],
} }
done: done:
/* Contents of evlog are not dynamically allocated so no eventlog_free(). */
free(evlog);
debug_return_bool(ret); debug_return_bool(ret);
} }