diff --git a/projects/rocr-runtime/runtime/hsa-runtime/libamdhsacode/amd_hsa_code_util.cpp b/projects/rocr-runtime/runtime/hsa-runtime/libamdhsacode/amd_hsa_code_util.cpp index 150840dd46..a1247de7f7 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/libamdhsacode/amd_hsa_code_util.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/libamdhsacode/amd_hsa_code_util.cpp @@ -957,12 +957,8 @@ int OpenTempFile(const char* prefix) #ifdef _WIN32 char dir[MAX_PATH+1]; if (!GetTempPath(sizeof(dir), dir)) { return -1; } -#else // _WIN32 - char *dir = NULL; -#endif // _WIN32 char *name = _tempnam(dir, tname.c_str()); if (!name) { return -1; } -#ifdef _WIN32 HANDLE h = CreateFile( name, GENERIC_READ | GENERIC_WRITE, @@ -975,10 +971,10 @@ int OpenTempFile(const char* prefix) if (h == INVALID_HANDLE_VALUE) { continue; } return _open_osfhandle((intptr_t)h, 0); #else // _WIN32 - int d = _open(name, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); - if (d < 0) { free(name); continue; } - if (unlink(name) < 0) { free(name); _close(d); return -1; } - free(name); + tname += "XXXXXX"; + int d = mkstemp((char*)tname.c_str()); + if (d < 0) { continue; } + if (unlink(tname.c_str()) < 0) { _close(d); return -1; } return d; #endif // _WIN32 }