mirror of
https://github.com/sudo-project/sudo.git
synced 2025-08-22 09:57:41 +00:00
journal_fdopen: free journal_path and close journal before setting
Fixes a potential resource leak that currently cannot happen. Quiets a warning from Infer.
This commit is contained in:
parent
a37ecb2666
commit
a0d9963fe6
@ -70,6 +70,7 @@ journal_fdopen(int fd, const char *journal_path,
|
||||
{
|
||||
debug_decl(journal_fdopen, SUDO_DEBUG_UTIL);
|
||||
|
||||
free(closure->journal_path);
|
||||
closure->journal_path = strdup(journal_path);
|
||||
if (closure->journal_path == NULL) {
|
||||
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
|
||||
@ -77,6 +78,8 @@ journal_fdopen(int fd, const char *journal_path,
|
||||
}
|
||||
|
||||
/* Defer fdopen() until last--it cannot be undone. */
|
||||
if (closure->journal != NULL)
|
||||
fclose(closure->journal);
|
||||
if ((closure->journal = fdopen(fd, "r+")) == NULL) {
|
||||
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO,
|
||||
"unable to fdopen journal file %s", journal_path);
|
||||
|
Loading…
x
Reference in New Issue
Block a user