diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-09-27 16:29:03 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-09-27 16:29:03 -0400 |
commit | a84b874a027fd8007efc10e0602396c4b5da170c (patch) | |
tree | f7604930a6a604446408bea64574cf23697a0506 /src/utils.c | |
parent | 9f535ba4e016f02c6d1bca45d6adfd04a036c9c1 (diff) | |
download | stasis-a84b874a027fd8007efc10e0602396c4b5da170c.tar.gz |
Fix leak
* When strdup fails and the temporary file handle is open, close the handle and die.
* reported by @kmacdonald-stsci
Diffstat (limited to 'src/utils.c')
-rw-r--r-- | src/utils.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c index 3a98f28..e037088 100644 --- a/src/utils.c +++ b/src/utils.c @@ -468,12 +468,23 @@ char *xmkstemp(FILE **fp, const char *mode) { fd = mkstemp(t_name); *fp = fdopen(fd, mode); if (!*fp) { + // unable to open, die if (fd > 0) close(fd); *fp = NULL; 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. + } return path; } |