aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2026-04-29 13:23:43 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2026-05-11 15:55:10 -0400
commit5561871e9fe902a6787bd13475b94e37831b923a (patch)
tree8c5fb65a31179f478239a228299cb24c300f1cf3 /src
parent345becc488f47cd2383dcca3fc08af464ba4f8ff (diff)
downloadstasis-5561871e9fe902a6787bd13475b94e37831b923a.tar.gz
fix_tox_conf: close file handles and allocations correctly
Diffstat (limited to 'src')
-rw-r--r--src/lib/core/utils.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/lib/core/utils.c b/src/lib/core/utils.c
index 221d507..78d713d 100644
--- a/src/lib/core/utils.c
+++ b/src/lib/core/utils.c
@@ -678,12 +678,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("unable to create temporary file");
+ if (fptemp) {
+ fclose(fptemp);
+ }
return -1;
}
@@ -692,6 +695,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;
}
}
@@ -729,6 +735,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;