diff --git a/src/util/os_create_dirpath.c b/src/util/os_create_dirpath.c index 5a7236ee5d..4c5aee643f 100644 --- a/src/util/os_create_dirpath.c +++ b/src/util/os_create_dirpath.c @@ -16,7 +16,7 @@ int ompi_os_create_dirpath(const char *path, const mode_t mode) { - char *pth, *bottom_up; + char *pth, *bottom_up, *tmp; struct stat buf; if (NULL == path) { /* protect ourselves from errors */ @@ -58,7 +58,9 @@ int ompi_os_create_dirpath(const char *path, const mode_t mode) while (strcmp(pth, ".") != 0 && stat(pth, &buf) != 0) { /* see if directory exists, or if we've reached the top */ strcat(bottom_up, basename(pth)); /* doesn't exist yet, so save this name */ strcat(bottom_up, ompi_system_info.path_sep); - strcpy(pth, dirname(pth)); /* "pop" the directory tree */ + tmp = strdup(pth); + strcpy(pth, dirname(tmp)); /* "pop" the directory tree */ + free(tmp); } /* okay, ready to build from the top down */ diff --git a/src/util/session_dir.c b/src/util/session_dir.c index a72eaed91c..a948a481d3 100644 --- a/src/util/session_dir.c +++ b/src/util/session_dir.c @@ -77,7 +77,7 @@ int ompi_session_dir(bool create, char *prfx, char *usr, char *hostid, { char *fulldirpath=NULL, *tmp=NULL, *hostname=NULL, *batchname=NULL; char *sessions=NULL, *frontend=NULL, *user=NULL, *universe=NULL; - char *prefix=NULL; + char *prefix=NULL, *sav=NULL; int return_code; /* ensure that system info is set */ @@ -222,14 +222,18 @@ int ompi_session_dir(bool create, char *prfx, char *usr, char *hostid, if (NULL == ompi_process_info.proc_session_dir && NULL != proc) { ompi_process_info.proc_session_dir = strdup(fulldirpath); + sav = strdup(fulldirpath); free(fulldirpath); - fulldirpath = strdup(dirname(ompi_process_info.proc_session_dir)); + fulldirpath = strdup(dirname(sav)); + free(sav); } if (NULL == ompi_process_info.job_session_dir && NULL != job) { ompi_process_info.job_session_dir = strdup(fulldirpath); + sav = strdup(fulldirpath); free(fulldirpath); - fulldirpath = strdup(dirname(ompi_process_info.job_session_dir)); + fulldirpath = strdup(dirname(sav)); + free(sav); } if (NULL == ompi_process_info.universe_session_dir) {