]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
Windows: fixup gettmpdir()
authorJeffrey Altman <jaltman@your-file-system.com>
Fri, 14 Jan 2011 05:15:10 +0000 (00:15 -0500)
committerDerrick Brashear <shadow@dementia.org>
Thu, 3 Feb 2011 11:45:35 +0000 (03:45 -0800)
Use InterlockedCompareExchangePointer for hostparse()
instead of fudging it and leaking memory.

If the max path length is MAX_PATH must allocate MAX_PATH+1.

Reviewed-on: http://gerrit.openafs.org/3658
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@openafs.org>
Tested-by: Jeffrey Altman <jaltman@openafs.org>
(cherry picked from commit a61a719d35cd6008f35c4f5cb8aaa83453d1d8c1)

Change-Id: I2183cd52298ea1d1204102fee66dea4755de3b41
Reviewed-on: http://gerrit.openafs.org/3820
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementia.org>
src/util/hostparse.c

index f1da7477edda4f815d38e926f5d5208a5568f3d6..2462931cebe4791448127d1d9bd2e69ee3955e98 100644 (file)
@@ -253,11 +253,11 @@ gettmpdir(void)
 
     if (saveTmpDir == NULL) {
        /* initialize global temporary directory string */
-       char *dirp = (char *)malloc(MAX_PATH);
+       char *dirp = (char *)malloc(MAX_PATH+1);
        int freeDirp = 1;
 
        if (dirp != NULL) {
-           DWORD pathLen = GetTempPath(MAX_PATH, dirp);
+           DWORD pathLen = GetTempPath(MAX_PATH+1, dirp);
 
            if (pathLen == 0 || pathLen > MAX_PATH) {
                /* can't get tmp path; get cur work dir */
@@ -279,7 +279,7 @@ gettmpdir(void)
                }
            }
        }
-       /* dirp != NULL */
+
        if (dirp != NULL) {
            FilepathNormalize(dirp);
        } else {
@@ -288,28 +288,12 @@ gettmpdir(void)
            freeDirp = 0;
        }
 
-       /* atomically initialize shared buffer pointer IF still null */
-
-#if 0
-       if (InterlockedCompareExchange(&saveTmpDir, dirp, NULL) != NULL) {
-           /* shared buffer pointer already initialized by another thread */
-           if (freeDirp) {
-               free(dirp);
-           }
-       }                       /* interlock xchng */
-#endif
-
-       /* Above is what we really want to do, but Windows 95 does not have
-        * InterlockedCompareExchange().  So we just atomically swap
-        * the buffer pointer values but we do NOT deallocate the
-        * previously installed buffer, if any, in case it is in use.
-        */
-#ifdef _WIN64
-       InterlockedExchange64((LONGLONG)(INT_PTR)&saveTmpDir, (LONGLONG) dirp);
-#else
-       InterlockedExchange((LONG) & saveTmpDir, (LONG) dirp);
-#endif
-
+        /* atomically initialize shared buffer pointer IF still null */
+        if (InterlockedCompareExchangePointer(&saveTmpDir, dirp, NULL) != NULL) {
+            /* shared buffer pointer already initialized by another thread */
+            if (freeDirp)
+                free(dirp);
+        }
     }
     /* if (!saveTmpDir) */
     tmpdirp = saveTmpDir;