From: Oliver Kurth Date: Fri, 15 Sep 2017 18:23:50 +0000 (-0700) Subject: lib/file: Must be errno safe X-Git-Tag: stable-10.2.0~111 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3b80a0df4bac2f5de52117096a482ab3f490f52a;p=thirdparty%2Fopen-vm-tools.git lib/file: Must be errno safe lib/file is documented to be safe about returning errno. This is true on Window and Posix platforms. We've had a bug where free can change errno. We created Posix_Free to protect errno but haven't used it consistently. Make lib/file use Posix_Free universally. --- diff --git a/open-vm-tools/lib/file/file.c b/open-vm-tools/lib/file/file.c index 8cfa2902a..45418dddc 100644 --- a/open-vm-tools/lib/file/file.c +++ b/open-vm-tools/lib/file/file.c @@ -483,7 +483,7 @@ GetOldMachineID(void) p = Util_SafeStrdup(encodedMachineID); if (Atomic_ReadIfEqualWritePtr(&atomic, NULL, p)) { - free(p); + Posix_Free(p); } machineID = Atomic_ReadPtr(&atomic); @@ -552,7 +552,7 @@ FileLockGetMachineID(void) p = Util_SafeStrdup(GetOldMachineID()); } else { p = Str_SafeAsprintf(NULL, "uuid=%s", q); - free(q); + Posix_Free(q); /* Surpress any whitespace. */ for (q = p; *q; q++) { @@ -563,7 +563,7 @@ FileLockGetMachineID(void) } if (Atomic_ReadIfEqualWritePtr(&atomic, NULL, p)) { - free(p); + Posix_Free(p); } machineID = Atomic_ReadPtr(&atomic); @@ -610,7 +610,7 @@ OldMachineIDMatch(const char *first, // IN: } } result = Base64_Decode(q, rawMachineID_1, sizeof rawMachineID_1, &len); - free(q); + Posix_Free(q); if ((result == FALSE) || (len != 12)) { Warning("%s: unexpected decode problem #1 (%s)\n", __FUNCTION__, @@ -625,7 +625,7 @@ OldMachineIDMatch(const char *first, // IN: } } result = Base64_Decode(q, rawMachineID_2, sizeof rawMachineID_2, &len); - free(q); + Posix_Free(q); if ((result == FALSE) || (len != 12)) { Warning("%s: unexpected decode problem #2 (%s)\n", __FUNCTION__, @@ -944,7 +944,7 @@ FileCopyTree(const char *srcName, // IN: break; } - free(dstFilename); + Posix_Free(dstFilename); } else { err = Err_Errno(); Msg_Append(MSGID(File.CopyTree.stat.failure) @@ -953,7 +953,7 @@ FileCopyTree(const char *srcName, // IN: Err_SetErrno(err); } - free(srcFilename); + Posix_Free(srcFilename); } Util_FreeStringList(fileList, numFiles); @@ -1323,7 +1323,7 @@ File_MoveTree(const char *srcName, // IN: "There is not enough space in the file system to " "move the directory tree. Free %s and try again.", spaceStr); - free(spaceStr); + Posix_Free(spaceStr); return FALSE; } } @@ -1497,7 +1497,7 @@ File_GetSizeEx(const char *pathName) // IN: char *fileName = File_PathJoin(pathName, fileList[i]); int64 fileSize = File_GetSizeEx(fileName); - free(fileName); + Posix_Free(fileName); if (fileSize != -1) { totalSize += fileSize; @@ -1590,7 +1590,7 @@ File_CreateDirectoryHierarchyEx(const char *pathName, // IN: index = Unicode_LengthInCodePoints(volume); - free(volume); + Posix_Free(volume); if (index >= length) { return File_IsDirectory(pathName); @@ -1651,7 +1651,7 @@ File_CreateDirectoryHierarchyEx(const char *pathName, // IN: } #endif - free(temp); + Posix_Free(temp); if (failed) { return FALSE; @@ -1811,10 +1811,10 @@ FileDeleteDirectoryTree(const char *pathName, // IN: directory to delete sawFileError = TRUE; } - free(curPath); + Posix_Free(curPath); } - free(base); + Posix_Free(base); if (!contentOnly) { /* @@ -1939,7 +1939,7 @@ File_FindFileInSearchPath(const char *fileIn, // IN: goto done; } - free(cur); + Posix_Free(cur); cur = NULL; if (full) { @@ -1986,7 +1986,7 @@ File_FindFileInSearchPath(const char *fileIn, // IN: break; } - free(cur); + Posix_Free(cur); cur = NULL; tok = strtok_r(NULL, FILE_SEARCHPATHTOKEN, &saveptr); @@ -2004,14 +2004,14 @@ done: } } - free(cur); + Posix_Free(cur); } else { found = FALSE; } - free(sp); - free(dir); - free(file); + Posix_Free(sp); + Posix_Free(dir); + Posix_Free(file); return found; } @@ -2232,7 +2232,7 @@ FileRotateByRename(const char *fileName, // IN: full path to file } ASSERT(dst != fileName); - free(dst); + Posix_Free(dst); dst = src; } } @@ -2348,7 +2348,7 @@ FileRotateByRenumber(const char *filePath, // IN: full path to file fileNumbers[nFound++] = curNr; } - free(fileList[i]); + Posix_Free(fileList[i]); } if (nFound > 0) { @@ -2372,7 +2372,7 @@ FileRotateByRenumber(const char *filePath, // IN: full path to file } if (newFilePath == NULL || result == -1) { - free(tmp); + Posix_Free(tmp); } else { *newFilePath = tmp; } @@ -2387,17 +2387,17 @@ FileRotateByRenumber(const char *filePath, // IN: full path to file Log(LGPFX" %s: failed to remove %s: %s\n", __FUNCTION__, tmp, Msg_ErrString()); } - free(tmp); + Posix_Free(tmp); } } cleanup: - free(fileNumbers); - free(fileList); - free(fmtString); - free(baseDir); - free(baseName); - free(fullPathNoExt); + Posix_Free(fileNumbers); + Posix_Free(fileList); + Posix_Free(fmtString); + Posix_Free(baseDir); + Posix_Free(baseName); + Posix_Free(fullPathNoExt); } @@ -2454,7 +2454,7 @@ File_Rotate(const char *fileName, // IN: original file FileRotateByRename(fileName, baseName, ext, n, newFileName); } - free(baseName); + Posix_Free(baseName); } @@ -2532,8 +2532,8 @@ File_ContainSymLink(const char *pathName) // IN: } } - free(path); - free(base); + Posix_Free(path); + Posix_Free(base); return retValue; } diff --git a/open-vm-tools/lib/file/fileIO.c b/open-vm-tools/lib/file/fileIO.c index 6432f72a2..1c3657235 100644 --- a/open-vm-tools/lib/file/fileIO.c +++ b/open-vm-tools/lib/file/fileIO.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 1998-2016 VMware, Inc. All rights reserved. + * Copyright (C) 1998-2017 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -231,7 +231,7 @@ FileIO_Cleanup(FileIODescriptor *fd) // IN/OUT: ASSERT(fd != NULL); if (fd->fileName) { - free(fd->fileName); + Posix_Free(fd->fileName); fd->fileName = NULL; } } @@ -530,7 +530,7 @@ FileIO_CloseAndUnlink(FileIODescriptor *fd) // IN: } } - free(path); + Posix_Free(path); return ret; } @@ -669,7 +669,7 @@ FileIO_AtomicTempPath(const char *path) // IN: return NULL; } retPath = Unicode_Join(srcPath, "~", NULL); - free(srcPath); + Posix_Free(srcPath); return retPath; } @@ -770,7 +770,7 @@ FileIO_AtomicTempFile(FileIODescriptor *fileFD, // IN: } #endif - free(tempPath); + Posix_Free(tempPath); return FILEIO_SUCCESS; bail: @@ -788,7 +788,7 @@ bail: ASSERT(ret == 0); #endif } - free(tempPath); + Posix_Free(tempPath); return status; } @@ -932,13 +932,13 @@ FileIO_AtomicUpdateEx(FileIODescriptor *newFD, // IN/OUT: file IO descriptor } swapdone: - free(args); - free(dirName); - free(fileName); - free(dstDirName); - free(dstFileName); - free(currPath); - free(newPath); + Posix_Free(args); + Posix_Free(dirName); + Posix_Free(fileName); + Posix_Free(dstDirName); + Posix_Free(dstFileName); + Posix_Free(currPath); + Posix_Free(newPath); errno = savedErrno; return ret; @@ -994,8 +994,8 @@ swapdone: currFD->win32 = tmpFD.win32; FileIO_Cleanup(&tmpFD); - free(currPath); - free(newPath); + Posix_Free(currPath); + Posix_Free(newPath); errno = savedErrno; return ret; diff --git a/open-vm-tools/lib/file/fileIOPosix.c b/open-vm-tools/lib/file/fileIOPosix.c index 8efa62f75..c8ed34201 100644 --- a/open-vm-tools/lib/file/fileIOPosix.c +++ b/open-vm-tools/lib/file/fileIOPosix.c @@ -691,7 +691,7 @@ ProxyUse(const char *pathName, // IN: temp = Unicode_Substr(pathName, 0, index + 1); path = Unicode_Append(temp, "."); - free(temp); + Posix_Free(temp); } /* @@ -713,7 +713,7 @@ ProxyUse(const char *pathName, // IN: *useProxy = TRUE; } - free(path); + Posix_Free(path); return 0; } @@ -1545,7 +1545,7 @@ FileIODecoalesce( if (filePosixOptions.aligned || flags & FILEIO_OPEN_UNBUFFERED) { FileIOAligned_Free(coVec->iov_base); } else { - free(coVec->iov_base); + Posix_Free(coVec->iov_base); } } @@ -2919,7 +2919,7 @@ FileIO_SupportsPrealloc(const char *pathName, // IN: statBuf.f_type == EXT4_SUPER_MAGIC) { ret = TRUE; } - free(fullPath); + Posix_Free(fullPath); } #endif diff --git a/open-vm-tools/lib/file/fileLockPosix.c b/open-vm-tools/lib/file/fileLockPosix.c index 1962c4365..fecfcaa28 100644 --- a/open-vm-tools/lib/file/fileLockPosix.c +++ b/open-vm-tools/lib/file/fileLockPosix.c @@ -518,8 +518,8 @@ FileLock_LockDevice(const char *deviceName) // IN: } exit: - free(lockFileName); - free(lockFileLink); + Posix_Free(lockFileName); + Posix_Free(lockFileLink); return status; } @@ -562,12 +562,12 @@ FileLock_UnlockDevice(const char *deviceName) // IN: if (ret < 0) { Log(LGPFX" Cannot remove lock file %s (%s).\n", path, Err_Errno2String(saveErrno)); - free(path); + Posix_Free(path); return FALSE; } - free(path); + Posix_Free(path); return TRUE; } @@ -1026,7 +1026,7 @@ FileLockValidExecutionID(const char *executionID) // IN: ASSERT(gotProcData); // We built it; it had better be good ASSERT(procPID == filePID); // This better match what we started with... - free(procDescriptor); + Posix_Free(procDescriptor); if ((fileCreationTime != 0) && (procCreationTime != 0) && @@ -1079,9 +1079,9 @@ FileLockNormalizePath(const char *filePath) // IN: result = (fullPath == NULL) ? NULL : Unicode_Join(fullPath, DIRSEPS, fileName, NULL); - free(fullPath); - free(dirName); - free(fileName); + Posix_Free(fullPath); + Posix_Free(dirName); + Posix_Free(fileName); return result; } @@ -1137,7 +1137,7 @@ FileLock_Lock(const char *filePath, // IN: tokenPtr = FileLockIntrinsic(normalizedPath, !readOnly, maxWaitTimeMsec, &res); - free(normalizedPath); + Posix_Free(normalizedPath); } if (err != NULL) { @@ -1195,7 +1195,7 @@ FileLock_IsLocked(const char *filePath, // IN: } else { isLocked = FileLockIsLocked(normalizedPath, &res); - free(normalizedPath); + Posix_Free(normalizedPath); } if (err != NULL) { diff --git a/open-vm-tools/lib/file/fileLockPrimitive.c b/open-vm-tools/lib/file/fileLockPrimitive.c index 1324b8e24..1eb6708fb 100644 --- a/open-vm-tools/lib/file/fileLockPrimitive.c +++ b/open-vm-tools/lib/file/fileLockPrimitive.c @@ -200,7 +200,7 @@ FileLockRemoveLockingFile(const char *lockDir, // IN: } } - free(path); + Posix_Free(path); return err; } @@ -465,7 +465,7 @@ fixedUp: Str_Strcpy(buffer, newBuffer, requiredSize); - free(newBuffer); + Posix_Free(newBuffer); goto fixedUp; } @@ -484,7 +484,7 @@ fixedUp: memberValues->lockType = argv[3]; memberValues->memberName = Unicode_Duplicate(fileName); - free(path); + Posix_Free(path); return 0; @@ -511,7 +511,7 @@ corrupt: } bail: - free(path); + Posix_Free(path); return err; } @@ -650,7 +650,7 @@ FileLockLocationChecksum(const char *path) // IN: } #if defined(_WIN32) - free(value); + Posix_Free(value); #endif return Str_SafeAsprintf(NULL, "%u", hash); @@ -717,7 +717,7 @@ FileLockScanDirectory(const char *lockDir, // IN: goto bail; } - free(fileList[i]); + Posix_Free(fileList[i]); fileList[i] = NULL; continue; @@ -738,7 +738,7 @@ FileLockScanDirectory(const char *lockDir, // IN: } } - free(fileList[i]); + Posix_Free(fileList[i]); fileList[i] = NULL; } } @@ -805,8 +805,8 @@ FileLockScanDirectory(const char *lockDir, // IN: Log(LGPFX" %s discarding %s from %s': %s\n", __FUNCTION__, fileList[i], lockDir, dispose); - free(dispose); - free(memberValues.memberName); + Posix_Free(dispose); + Posix_Free(memberValues.memberName); err = FileLockRemoveLockingFile(lockDir, fileList[i]); if (err != 0) { @@ -824,7 +824,7 @@ FileLockScanDirectory(const char *lockDir, // IN: err = (*func)(lockDir, fileList[i], ptr, myValues); if (ptr == &memberValues) { - free(memberValues.memberName); + Posix_Free(memberValues.memberName); } if (err != 0) { @@ -836,8 +836,8 @@ bail: Util_FreeStringList(fileList, numEntries); - free(locationChecksum); - free(myExecutionID); + Posix_Free(locationChecksum); + Posix_Free(myExecutionID); return err; } @@ -917,15 +917,15 @@ FileLockScanner(const char *lockDir, // IN: temp = Unicode_Replace(path, index, 1, "M"); FileDeletionRobust(temp, FALSE); - free(temp); + Posix_Free(temp); temp = Unicode_Replace(path, index, 1, "E"); FileDeletionRobust(temp, FALSE); - free(temp); + Posix_Free(temp); FileRemoveDirectoryRobust(path); - free(path); + Posix_Free(path); remove = TRUE; } else { @@ -959,9 +959,9 @@ FileLockScanner(const char *lockDir, // IN: ptr = myValues->lockList; myValues->lockList = ptr->next; - free(ptr->dirName); + Posix_Free(ptr->dirName); - free(ptr); + Posix_Free(ptr); } return err; @@ -1021,8 +1021,8 @@ FileUnlockIntrinsic(FileLockToken *tokenPtr) // IN: Log(LGPFX" %s failed for '%s': %s\n", __FUNCTION__, tokenPtr->u.portable.lockFilePath, Err_Errno2String(err)); } - free(lockDir); - free(tokenPtr->u.portable.lockFilePath); + Posix_Free(lockDir); + Posix_Free(tokenPtr->u.portable.lockFilePath); } tokenPtr->u.portable.lockFilePath = NULL; // Just in case... @@ -1054,10 +1054,10 @@ FileUnlockIntrinsic(FileLockToken *tokenPtr) // IN: } } - free(tokenPtr->pathName); + Posix_Free(tokenPtr->pathName); tokenPtr->signature = 0; // Just in case... tokenPtr->pathName = NULL; // Just in case... - free(tokenPtr); + Posix_Free(tokenPtr); return err; } @@ -1147,7 +1147,7 @@ FileLockWaitForPossession(const char *lockDir, // IN: } } - free(path); + Posix_Free(path); } return err; @@ -1332,11 +1332,11 @@ FileLockCreateEntryDirectory(const char *lockDir, // IN: temp = Unicode_Format("D%05u%s", randomNumber, FILELOCK_SUFFIX); *entryDirectory = Unicode_Join(lockDir, DIRSEPS, temp, NULL); - free(temp); + Posix_Free(temp); temp = Unicode_Format("E%05u%s", randomNumber, FILELOCK_SUFFIX); *entryFilePath = Unicode_Join(lockDir, DIRSEPS, temp, NULL); - free(temp); + Posix_Free(temp); *memberFilePath = Unicode_Join(lockDir, DIRSEPS, *memberName, NULL); @@ -1378,10 +1378,10 @@ FileLockCreateEntryDirectory(const char *lockDir, // IN: } } - free(*entryDirectory); - free(*entryFilePath); - free(*memberFilePath); - free(*memberName); + Posix_Free(*entryDirectory); + Posix_Free(*entryFilePath); + Posix_Free(*memberFilePath); + Posix_Free(*memberName); *entryDirectory = NULL; *entryFilePath = NULL; @@ -1390,10 +1390,10 @@ FileLockCreateEntryDirectory(const char *lockDir, // IN: } if (err != 0) { - free(*entryDirectory); - free(*entryFilePath); - free(*memberFilePath); - free(*memberName); + Posix_Free(*entryDirectory); + Posix_Free(*entryFilePath); + Posix_Free(*memberFilePath); + Posix_Free(*memberName); *entryDirectory = NULL; *entryFilePath = NULL; @@ -1597,9 +1597,9 @@ FileLockIntrinsicMandatory(const char *pathName, // IN: } else { *err = FileMapErrorToErrno(__FUNCTION__, errnum); } - free(tokenPtr->pathName); + Posix_Free(tokenPtr->pathName); ASSERT(!FileIO_IsValid(&tokenPtr->u.mandatory.lockFd)); - free(tokenPtr); + Posix_Free(tokenPtr); return NULL; } @@ -1769,8 +1769,8 @@ FileLockIntrinsicPortable(const char *pathName, // IN: bail: - free(entryDirectory); - free(entryFilePath); + Posix_Free(entryDirectory); + Posix_Free(entryFilePath); if (*err == 0) { tokenPtr = Util_SafeMalloc(sizeof *tokenPtr); @@ -1780,7 +1780,7 @@ bail: tokenPtr->pathName = Unicode_Duplicate(pathName); tokenPtr->u.portable.lockFilePath = memberFilePath; } else { - free(memberFilePath); + Posix_Free(memberFilePath); tokenPtr = NULL; if (*err == EAGAIN) { @@ -1864,12 +1864,12 @@ FileLockIntrinsic(const char *pathName, // IN: tokenPtr = FileLockIntrinsicPortable(pathName, lockBase, &myValues, err); - free(myValues.memberName); - free(myValues.locationChecksum); - free(myValues.executionID); + Posix_Free(myValues.memberName); + Posix_Free(myValues.locationChecksum); + Posix_Free(myValues.executionID); } - free(lockBase); + Posix_Free(lockBase); return tokenPtr; } @@ -2031,7 +2031,7 @@ FileLockIsLocked(const char *pathName, // IN: isLocked = FileLockIsLockedPortable(lockBase, err); } - free(lockBase); + Posix_Free(lockBase); return isLocked; } diff --git a/open-vm-tools/lib/file/filePosix.c b/open-vm-tools/lib/file/filePosix.c index e36c8d432..6f3d7b2fb 100644 --- a/open-vm-tools/lib/file/filePosix.c +++ b/open-vm-tools/lib/file/filePosix.c @@ -221,7 +221,7 @@ FileDeletion(const char *pathName, // IN: } else { err = (Posix_Unlink(linkPath) == -1) ? errno : 0; - free(linkPath); + Posix_Free(linkPath); /* Ignore a file that has already disappeared */ if (err != ENOENT) { @@ -469,7 +469,7 @@ File_Cwd(const char *drive) // IN: break; } - free(buffer); + Posix_Free(buffer); buffer = NULL; if (errno != ERANGE) { @@ -494,7 +494,7 @@ File_Cwd(const char *drive) // IN: path = Unicode_Alloc(buffer, STRING_ENCODING_DEFAULT); - free(buffer); + Posix_Free(buffer); return path; } @@ -555,7 +555,7 @@ File_StripFwdSlashes(const char *pathName) // IN: result = Unicode_AllocWithUTF8(path); - free(path); + Posix_Free(path); return result; } @@ -628,15 +628,15 @@ File_FullPath(const char *pathName) // IN: } ret = Unicode_Join(realDir, DIRSEPS, file, NULL); - free(dir); - free(file); - free(realDir); + Posix_Free(dir); + Posix_Free(file); + Posix_Free(realDir); } - free(path); + Posix_Free(path); } - free(cwd); + Posix_Free(cwd); return ret; } @@ -854,7 +854,7 @@ File_SetTimes(const char *pathName, // IN: if (err != 0) { Log(LGPFX" %s: error stating file \"%s\": %s\n", __FUNCTION__, pathName, Err_Errno2String(err)); - free(path); + Posix_Free(path); return FALSE; } @@ -890,7 +890,7 @@ File_SetTimes(const char *pathName, // IN: err = (utimes(path, times) == -1) ? errno : 0; - free(path); + Posix_Free(path); if (err != 0) { Log(LGPFX" %s: utimes error on file \"%s\": %s\n", __FUNCTION__, @@ -979,22 +979,22 @@ FilePosixGetParent(char **canPath) // IN/OUT: Canonical file path File_GetPathName(*canPath, &pathName, &baseName); - free(*canPath); + Posix_Free(*canPath); if (Unicode_IsEmpty(pathName)) { /* empty string which denotes "/" */ - free(pathName); + Posix_Free(pathName); *canPath = Unicode_Duplicate("/"); } else { if (Unicode_IsEmpty(baseName)) { // Directory File_GetPathName(pathName, canPath, NULL); - free(pathName); + Posix_Free(pathName); } else { // File *canPath = pathName; } } - free(baseName); + Posix_Free(baseName); return FALSE; } @@ -1063,7 +1063,7 @@ FileGetStats(const char *pathName, // IN: FilePosixGetParent(&dupPath); } - free(dupPath); + Posix_Free(dupPath); return retval; } @@ -1108,7 +1108,7 @@ File_GetFreeSpace(const char *pathName, // IN: File name ret = -1; } - free(fullPath); + Posix_Free(fullPath); return ret; } @@ -1172,7 +1172,7 @@ File_GetVMFSAttributes(const char *pathName, // IN: File/dir to tes Log(LGPFX" %s: could not open %s: %s\n", __func__, pathName, Err_Errno2String(errno)); ret = -1; - free(*fsAttrs); + Posix_Free(*fsAttrs); *fsAttrs = NULL; goto bail; } @@ -1181,15 +1181,15 @@ File_GetVMFSAttributes(const char *pathName, // IN: File/dir to tes if (ret == -1) { Log(LGPFX" %s: Could not get volume attributes (ret = %d): %s\n", __func__, ret, Err_Errno2String(errno)); - free(*fsAttrs); + Posix_Free(*fsAttrs); *fsAttrs = NULL; } close(fd); bail: - free(fullPath); - free(directory); + Posix_Free(fullPath); + Posix_Free(directory); return ret; } @@ -1305,7 +1305,7 @@ File_GetVMFSVersion(const char *pathName, // IN: File name to test } if (fsAttrs) { - free(fsAttrs); + Posix_Free(fsAttrs); } exit: @@ -1351,7 +1351,7 @@ File_GetVMFSBlockSize(const char *pathName, // IN: File name to test } if (fsAttrs) { - free(fsAttrs); + Posix_Free(fsAttrs); } exit: @@ -1421,7 +1421,7 @@ File_GetVMFSMountInfo(const char *pathName, // IN: *remoteMountPoint = NULL; } - free(fsAttrs); + Posix_Free(fsAttrs); } return ret; @@ -1464,7 +1464,7 @@ FileIsVMFS(const char *pathName) // IN: } if (fsAttrs) { - free(fsAttrs); + Posix_Free(fsAttrs); } #endif @@ -1564,8 +1564,8 @@ File_SupportsOptimisticLock(const char *pathName) // IN: } File_GetPathName(fullPath, &dir, NULL); res = File_GetVMFSFSType(dir, -1, &fsTypeNum); - free(tempPath); - free(dir); + Posix_Free(tempPath); + Posix_Free(dir); return (res == 0) ? IS_VMFS_FSTYPENUM(fsTypeNum) : FALSE; #else @@ -1610,7 +1610,7 @@ File_GetCapacity(const char *pathName) // IN: Path name ret = -1; } - free(fullPath); + Posix_Free(fullPath); return ret; } @@ -1661,13 +1661,13 @@ File_GetUniqueFileSystemID(char const *path) // IN: File path char devfsName[FILE_MAXPATH]; if (sscanf(existPath, DEVFS_MOUNT_PATH "%[^/]%*s", devfsName) == 1) { - free(existPath); - free(canPath); + Posix_Free(existPath); + Posix_Free(canPath); return Str_SafeAsprintf(NULL, "%s/%s", DEVFS_MOUNT_POINT, devfsName); } } - free(existPath); + Posix_Free(existPath); if (canPath == NULL) { return NULL; @@ -1681,7 +1681,7 @@ File_GetUniqueFileSystemID(char const *path) // IN: File path */ if (strncmp(canPath, VCFS_MOUNT_POINT, strlen(VCFS_MOUNT_POINT)) != 0 || sscanf(canPath, VCFS_MOUNT_PATH "%[^/]%*s", vmfsVolumeName) != 1) { - free(canPath); + Posix_Free(canPath); goto exit; } @@ -1703,13 +1703,13 @@ File_GetUniqueFileSystemID(char const *path) // IN: File path unique = Str_SafeAsprintf(NULL, "%s/%s/%s", VCFS_MOUNT_POINT, vmfsVolumeName, fsAttrs->name); - free(fsAttrs); - free(canPath); + Posix_Free(fsAttrs); + Posix_Free(canPath); return unique; } - free(fsAttrs); + Posix_Free(fsAttrs); } - free(canPath); + Posix_Free(canPath); return Str_SafeAsprintf(NULL, "%s/%s", VCFS_MOUNT_POINT, vmfsVolumeName); @@ -1799,7 +1799,7 @@ retry: !mnt.mnt_type || !mnt.mnt_opts) { size += 4 * FILE_MAXPATH; ASSERT(size <= 32 * FILE_MAXPATH); - free(buf); + Posix_Free(buf); endmntent(f); goto retry; } @@ -1834,7 +1834,7 @@ retry: // 'canPath' is not a mount point. endmntent(f); - free(buf); + Posix_Free(buf); return ret; #endif @@ -1880,7 +1880,7 @@ FilePosixGetBlockDevice(char const *path) // IN: File path #if defined(__APPLE__) failed = statfs(existPath, &buf) == -1; - free(existPath); + Posix_Free(existPath); if (failed) { return NULL; } @@ -1888,13 +1888,13 @@ FilePosixGetBlockDevice(char const *path) // IN: File path return Util_SafeStrdup(buf.f_mntfromname); #else realPath = Posix_RealPath(existPath); - free(existPath); + Posix_Free(existPath); if (realPath == NULL) { return NULL; } Str_Strcpy(canPath, realPath, sizeof canPath); - free(realPath); + Posix_Free(realPath); retry: Str_Strcpy(canPath2, canPath, sizeof canPath2); @@ -1955,7 +1955,7 @@ retry: Str_Strcpy(canPath, ptr, sizeof canPath); } - free(ptr); + Posix_Free(ptr); /* * There could be a series of these chained together. It is @@ -1980,7 +1980,7 @@ retry: x = Util_SafeStrdup(canPath); failed = FilePosixGetParent(&x); Str_Strcpy(canPath, x, sizeof canPath); - free(x); + Posix_Free(x); /* * Prevent an infinite loop in case FilePosixLookupMountPoint() even @@ -2249,8 +2249,8 @@ File_Replace(const char *oldName, // IN: old file result = TRUE; bail: - free(newPath); - free(oldPath); + Posix_Free(newPath); + Posix_Free(oldPath); errno = status; @@ -2352,7 +2352,7 @@ FilePosixCreateTestGetMaxOrSupportsFileSize(const char *dirName, // IN: test dir temp = Unicode_Append(dirName, "/.vmBigFileTest"); posixFD = File_MakeSafeTemp(temp, &path); - free(temp); + Posix_Free(temp); if (posixFD == -1) { Log(LGPFX" %s: Failed to create temporary file in dir: %s\n", __func__, @@ -2369,7 +2369,7 @@ FilePosixCreateTestGetMaxOrSupportsFileSize(const char *dirName, // IN: test dir FileIO_Close(&fd); File_Unlink(path); - free(path); + Posix_Free(path); return retVal; } @@ -2443,8 +2443,8 @@ FileVMKGetMaxFileSize(const char *pathName, // IN: close(fd); bail: - free(fullPath); - free(dirPath); + Posix_Free(fullPath); + Posix_Free(dirPath); return retval; } @@ -2521,12 +2521,12 @@ FileVMKGetMaxOrSupportsFileSize(const char *pathName, // IN: } else { Log(LGPFX" %s: Unsupported filesystem version, %u\n", __func__, fsAttrs->versionNumber); - free(fsAttrs); + Posix_Free(fsAttrs); return FALSE; } - free(fsAttrs); + Posix_Free(fsAttrs); if (maxFileSize == -1) { Log(LGPFX" %s: Failed to figure out the max file size for %s\n", __func__, pathName); @@ -2549,7 +2549,7 @@ FileVMKGetMaxOrSupportsFileSize(const char *pathName, // IN: if (fullPath == NULL) { Log(LGPFX" %s: Error acquiring full path\n", __func__); - free(fsAttrs); + Posix_Free(fsAttrs); return FALSE; } @@ -2560,9 +2560,9 @@ FileVMKGetMaxOrSupportsFileSize(const char *pathName, // IN: fileSize, getMaxFileSize); - free(fsAttrs); - free(fullPath); - free(parentPath); + Posix_Free(fsAttrs); + Posix_Free(fullPath); + Posix_Free(parentPath); return supported; } @@ -2661,10 +2661,10 @@ FileGetMaxOrSupportsFileSize(const char *pathName, // IN: retval = FilePosixCreateTestGetMaxOrSupportsFileSize(folderPath, fileSize, getMaxFileSize); - free(folderPath); + Posix_Free(folderPath); out: - free(fullPath); + Posix_Free(fullPath); return retval; } @@ -2817,7 +2817,7 @@ FileKeyDispose(const char *key, // IN: void *value, // IN: void *clientData) // IN: { - free((void *) key); + Posix_Free((void *) key); return 0; } @@ -2885,7 +2885,7 @@ File_ListDirectory(const char *pathName, // IN: Warning("%s: file '%s' in directory '%s' cannot be converted to " "UTF8\n", __FUNCTION__, pathName, id); - free(id); + Posix_Free(id); id = Unicode_Duplicate(UNICODE_SUBSTITUTION_CHAR UNICODE_SUBSTITUTION_CHAR @@ -2904,7 +2904,7 @@ File_ListDirectory(const char *pathName, // IN: if (HashTable_Insert(hash, id, NULL)) { count++; } else { - free(id); + Posix_Free(id); } } else { count++; @@ -2958,7 +2958,7 @@ File_WalkDirectoryEnd(WalkDirContext context) // IN: if (context->cnt > 0) { Util_FreeStringList(context->files, context->cnt); } - free(context); + Posix_Free(context); } } @@ -3108,7 +3108,7 @@ FileIsGroupsMember(gid_t gid) // IN: ret = FALSE; end: - free(members); + Posix_Free(members); return ret; } diff --git a/open-vm-tools/lib/file/fileStandAlone.c b/open-vm-tools/lib/file/fileStandAlone.c index 8c4362315..f67fd5690 100644 --- a/open-vm-tools/lib/file/fileStandAlone.c +++ b/open-vm-tools/lib/file/fileStandAlone.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 1998-2016 VMware, Inc. All rights reserved. + * Copyright (C) 1998-2017 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -299,19 +299,19 @@ File_SplitName(const char *pathName, // IN: if (volume) { *volume = vol; } else { - free(vol); + Posix_Free(vol); } if (directory) { *directory = dir; } else { - free(dir); + Posix_Free(dir); } if (base) { *base = bas; } else { - free(bas); + Posix_Free(bas); } } @@ -397,7 +397,7 @@ File_PathJoin(const char *dirName, // IN: newDir = File_StripSlashes(dirName); result = Unicode_Join(newDir, DIRSEPS, baseName, NULL); - free(newDir); + Posix_Free(newDir); return result; } @@ -442,7 +442,7 @@ File_GetPathName(const char *fullPath, // IN: File_SplitName(fullPath, &volume, pathName, baseName); if (pathName == NULL) { - free(volume); + Posix_Free(volume); return; } @@ -453,10 +453,10 @@ File_GetPathName(const char *fullPath, // IN: if (!Unicode_IsEmpty(volume)) { char *temp = Unicode_Append(volume, *pathName); - free(*pathName); + Posix_Free(*pathName); *pathName = temp; } - free(volume); + Posix_Free(volume); /* * Remove any trailing directory separator characters. @@ -474,7 +474,7 @@ File_GetPathName(const char *fullPath, // IN: if (curLen < len) { char *temp = Unicode_Substr(*pathName, 0, curLen); - free(*pathName); + Posix_Free(*pathName); *pathName = temp; } } @@ -530,16 +530,16 @@ File_StripSlashes(const char *path) // IN: i--; } - free(dir); + Posix_Free(dir); dir = Unicode_AllocWithLength(dir2, i, STRING_ENCODING_UTF8); - free(dir2); + Posix_Free(dir2); } result = Unicode_Join(volume, dir, base, NULL); - free(volume); - free(dir); - free(base); + Posix_Free(volume); + Posix_Free(dir); + Posix_Free(base); return result; } @@ -618,13 +618,13 @@ File_MapPathPrefix(const char *oldPath, // IN: * aren't allowed. */ - free(oldPrefix); - free(newPrefix); + Posix_Free(oldPrefix); + Posix_Free(newPrefix); return newPath; } - free(oldPrefix); - free(newPrefix); + Posix_Free(oldPrefix); + Posix_Free(newPrefix); } return NULL; @@ -770,7 +770,7 @@ File_ReplaceExtension(const char *pathName, // IN: } if (oldBase != base) { - free(oldBase); + Posix_Free(oldBase); } } @@ -780,8 +780,8 @@ File_ReplaceExtension(const char *pathName, // IN: result = Unicode_Join(path, DIRSEPS, base, newExtension, NULL); } - free(path); - free(base); + Posix_Free(path); + Posix_Free(base); return result; } diff --git a/open-vm-tools/lib/file/fileTemp.c b/open-vm-tools/lib/file/fileTemp.c index 6186eb9fe..0676c176d 100644 --- a/open-vm-tools/lib/file/fileTemp.c +++ b/open-vm-tools/lib/file/fileTemp.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2011-2016 VMware, Inc. All rights reserved. + * Copyright (C) 2011-2017 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -141,7 +141,7 @@ File_MakeTempEx2(const char *dir, // IN: char *fileName; /* construct suffixed pathname to use */ - free(path); + Posix_Free(path); path = NULL; /* @@ -160,7 +160,7 @@ File_MakeTempEx2(const char *dir, // IN: /* construct base full pathname to use */ path = Unicode_Join(dir, DIRSEPS, fileName, NULL); - free(fileName); + Posix_Free(fileName); if (createTempFile) { fd = Posix_Open(path, O_CREAT | O_EXCL | O_BINARY | O_RDWR, 0600); @@ -191,7 +191,7 @@ File_MakeTempEx2(const char *dir, // IN: } exit: - free(path); + Posix_Free(path); return fd; } @@ -299,7 +299,7 @@ File_MakeSafeTempDir(const char *prefix) // IN: File_MakeTempEx2(dir, FALSE, FileMakeTempExCreateNameFunc, (void *) effectivePrefix, &result); - free(dir); + Posix_Free(dir); } return result; @@ -344,8 +344,8 @@ File_MakeSafeTemp(const char *tag, // IN (OPT): fd = File_MakeTempEx(dir, fileName, presult); - free(dir); - free(fileName); + Posix_Free(dir); + Posix_Free(fileName); return fd; } @@ -403,8 +403,8 @@ File_DoesVolumeSupportAcls(const char *path) // IN: succeeded = TRUE; exit: - free(vol); - free(vol2); + Posix_Free(vol); + Posix_Free(vol2); #endif return succeeded; diff --git a/open-vm-tools/lib/file/fileTempPosix.c b/open-vm-tools/lib/file/fileTempPosix.c index ae4d6861a..c6d98786b 100644 --- a/open-vm-tools/lib/file/fileTempPosix.c +++ b/open-vm-tools/lib/file/fileTempPosix.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2004-2016 VMware, Inc. All rights reserved. + * Copyright (C) 2004-2017 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -86,7 +86,7 @@ FileTryDir(const char *dirName) // IN: Is this a writable directory? return edirName; } - free(edirName); + Posix_Free(edirName); } return NULL; @@ -122,7 +122,7 @@ FileGetTmpDir(Bool useConf) // IN: Use the config file? if (useConf) { dirName = (char *)LocalConfig_GetString(NULL, "tmpDirectory"); edirName = FileTryDir(dirName); - free(dirName); + Posix_Free(dirName); if (edirName != NULL) { return edirName; } @@ -154,7 +154,7 @@ FileGetTmpDir(Bool useConf) // IN: Use the config file? if (dirName != NULL) { edirName = FileTryDir(dirName); - free(dirName); + Posix_Free(dirName); if (edirName != NULL) { return edirName; } @@ -221,7 +221,7 @@ FileGetUserName(uid_t uid) // IN: if ((Posix_Getpwuid_r(uid, &pw, memPool, memPoolSize, &pw_p) != 0) || pw_p == NULL) { - free(memPool); + Posix_Free(memPool); Warning("%s: Unable to retrieve the username associated with " "user ID %u.\n", __FUNCTION__, uid); @@ -229,7 +229,7 @@ FileGetUserName(uid_t uid) // IN: } userName = strdup(pw_p->pw_name); - free(memPool); + Posix_Free(memPool); if (userName == NULL) { Warning("%s: Not enough memory.\n", __FUNCTION__); @@ -346,7 +346,7 @@ FileFindExistingSafeTmpDir(uid_t userId, // IN: numFiles = File_ListDirectory(baseTmpDir, &fileList); if (numFiles == -1) { - free(pattern); + Posix_Free(pattern); return NULL; } @@ -361,12 +361,12 @@ FileFindExistingSafeTmpDir(uid_t userId, // IN: break; } - free(path); + Posix_Free(path); } } Util_FreeStringList(fileList, numFiles); - free(pattern); + Posix_Free(pattern); return tmpDir; } @@ -422,12 +422,12 @@ FileCreateSafeTmpDir(uid_t userId, // IN: Warning("%s: Failed to create a safe temporary directory, path " "\"%s\". The maximum number of attempts was exceeded.\n", __FUNCTION__, tmpDir); - free(tmpDir); + Posix_Free(tmpDir); tmpDir = NULL; break; } - free(tmpDir); + Posix_Free(tmpDir); tmpDir = NULL; } @@ -532,7 +532,7 @@ File_GetSafeTmpDir(Bool useConf) // IN: * an acceptable one to use. */ - free(tmpDir); + Posix_Free(tmpDir); tmpDir = FileFindExistingSafeTmpDir(userId, userName, baseTmpDir); @@ -551,14 +551,14 @@ File_GetSafeTmpDir(Bool useConf) // IN: * future calls. */ - free(safeDir); + Posix_Free(safeDir); safeDir = Util_SafeStrdup(tmpDir); } exit: MXUser_ReleaseExclLock(lck); - free(baseTmpDir); - free(userName); + Posix_Free(baseTmpDir); + Posix_Free(userName); #endif return tmpDir;