diff options
| -rw-r--r-- | src/multiprocessing.c | 2 | ||||
| -rw-r--r-- | src/utils.c | 11 | 
2 files changed, 12 insertions, 1 deletions
| diff --git a/src/multiprocessing.c b/src/multiprocessing.c index 1320a2a..74ba981 100644 --- a/src/multiprocessing.c +++ b/src/multiprocessing.c @@ -117,7 +117,7 @@ struct MultiProcessingTask *mp_pool_task(struct MultiProcessingPool *pool, const      // Create a temporary file to act as our intermediate command script      FILE *tp = NULL; -    char *t_name; +    char *t_name = NULL;      t_name = xmkstemp(&tp, "w");      if (!t_name || !tp) {          return NULL; 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;  } | 
