aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2026-04-29 13:22:22 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2026-04-29 13:22:22 -0400
commit380f53de5c6fd6d065a764d387ceadcc2a8ac37e (patch)
tree6042b43cf338aefec43bc2662afa60462b264e99 /src/lib
parent0b70a93476a157b150417b5d8db85d1eb4c97806 (diff)
downloadstasis-380f53de5c6fd6d065a764d387ceadcc2a8ac37e.tar.gz
xmkstemp: UB, close handles correctly
* free tempfile
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/core/utils.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/lib/core/utils.c b/src/lib/core/utils.c
index 0c6880f..8e48df3 100644
--- a/src/lib/core/utils.c
+++ b/src/lib/core/utils.c
@@ -523,25 +523,25 @@ char *xmkstemp(FILE **fp, const char *mode) {
snprintf(t_name, sizeof(t_name), "%s/%s", tmpdir, "STASIS.XXXXXX");
fd = mkstemp(t_name);
+ if (fd < 0) {
+ SYSERROR("unable to create temporary file: %s", t_name);
+ return NULL;
+ }
*fp = fdopen(fd, mode);
if (!*fp) {
- // unable to open, die
- if (fd > 0)
- close(fd);
- *fp = NULL;
+ close(fd);
return NULL;
}
char *path = strdup(t_name);
if (!path) {
// strdup failed, die
- if (*fp) {
- // close the file handle
- fclose(*fp);
- *fp = NULL;
- }
- // fall through. path is NULL.
+ // close the file handle
+ fclose(*fp);
+ *fp = NULL;
+ return NULL;
}
+
return path;
}