diff options
| author | Joseph Hunkeler <jhunkeler@gmail.com> | 2026-04-29 13:23:43 -0400 |
|---|---|---|
| committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2026-04-29 13:23:43 -0400 |
| commit | 00dc955382a017d91f7071401e8c9beda241662e (patch) | |
| tree | 27d699983a323d9d250296093593d6e74cddad53 | |
| parent | d59a7ea05884ab4942963ba8ba317dcfea524287 (diff) | |
| download | stasis-00dc955382a017d91f7071401e8c9beda241662e.tar.gz | |
fix_tox_conf: close file handles and allocations correctly
| -rw-r--r-- | src/lib/core/utils.c | 9 |
1 files changed, 8 insertions, 1 deletions
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; |
