From a84b874a027fd8007efc10e0602396c4b5da170c Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Fri, 27 Sep 2024 16:29:03 -0400 Subject: Fix leak * When strdup fails and the temporary file handle is open, close the handle and die. * reported by @kmacdonald-stsci --- src/utils.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/utils.c') 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; } -- cgit