From 00dc955382a017d91f7071401e8c9beda241662e Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 29 Apr 2026 13:23:43 -0400 Subject: fix_tox_conf: close file handles and allocations correctly --- src/lib/core/utils.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lib/core/utils.c b/src/lib/core/utils.c index 047fa16..deeca91 100644 --- a/src/lib/core/utils.c +++ b/src/lib/core/utils.c @@ -671,12 +671,15 @@ int xml_pretty_print_in_place(const char *filename, const char *pretty_print_pro */ int fix_tox_conf(const char *filename, char **result, size_t maxlen) { struct INIFILE *toxini; - FILE *fptemp; + FILE *fptemp = NULL; // Create new temporary tox configuration file char *tempfile = xmkstemp(&fptemp, "w+"); if (!tempfile) { SYSERROR("%s", "unable to create temporary file"); + if (fptemp) { + fclose(fptemp); + } return -1; } @@ -685,6 +688,9 @@ int fix_tox_conf(const char *filename, char **result, size_t maxlen) { *result = calloc(maxlen, sizeof(**result)); if (!*result) { guard_free(tempfile); + if (fptemp) { + fclose(fptemp); + } return -1; } } @@ -722,6 +728,7 @@ int fix_tox_conf(const char *filename, char **result, size_t maxlen) { strlen(value) + strlen(with_posargs) + 1); guard_free(*result); guard_free(tempfile); + fclose(fptemp); return -1; } value = tmp; -- cgit