From: Oliver Kurth Date: Fri, 15 Sep 2017 18:23:27 +0000 (-0700) Subject: Make AsyncSocket_Close() idempotent; move dec-ref out of AsyncSocket_Close(). X-Git-Tag: stable-10.2.0~324 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1285fffabe27c98ab90012c5d89fd2d17bd48606;p=thirdparty%2Fopen-vm-tools.git Make AsyncSocket_Close() idempotent; move dec-ref out of AsyncSocket_Close(). Changes to common source files; not applicable to open-vm-tools. --- diff --git a/open-vm-tools/lib/asyncsocket/asyncSocketBase.c b/open-vm-tools/lib/asyncsocket/asyncSocketBase.c index d91deceb7..10fc2c808 100644 --- a/open-vm-tools/lib/asyncsocket/asyncSocketBase.c +++ b/open-vm-tools/lib/asyncsocket/asyncSocketBase.c @@ -309,6 +309,7 @@ AsyncSocketInitSocket(AsyncSocket *s, // IN/OUT s->id = Atomic_ReadInc32(&nextid); s->refCount = 1; s->vt = vtable; + s->inited = TRUE; if (pollParams) { s->pollParams = *pollParams; } else { @@ -320,6 +321,38 @@ AsyncSocketInitSocket(AsyncSocket *s, // IN/OUT } +/* + *----------------------------------------------------------------------------- + * + * AsyncSocketTeardownSocket -- + * + * Tear down the AsyncSocket base struct. Currently this just + * clears the inited flag and releases the initial (user) refcount. + * + * Results: + * None. + * + * Side effects: + * None. + * + *----------------------------------------------------------------------------- + */ + +void +AsyncSocketTeardownSocket(AsyncSocket *asock) // IN/OUT +{ + /* + * Release the initial refcount created when we initialize the + * socket struct. + */ + ASSERT(AsyncSocketIsLocked(asock)); + ASSERT(asock->refCount >= 1); + ASSERT(asock->inited); + asock->inited = FALSE; + AsyncSocketRelease(asock); +} + + /* *---------------------------------------------------------------------------- * diff --git a/open-vm-tools/lib/asyncsocket/asyncSocketBase.h b/open-vm-tools/lib/asyncsocket/asyncSocketBase.h index 13126fe40..1f176b5c6 100644 --- a/open-vm-tools/lib/asyncsocket/asyncSocketBase.h +++ b/open-vm-tools/lib/asyncsocket/asyncSocketBase.h @@ -50,6 +50,7 @@ struct AsyncSocket { AsyncSocketPollParams pollParams; AsyncSocketState state; + Bool inited; Bool errorSeen; AsyncSocketErrorFn errorFn; void *errorClientData; @@ -67,6 +68,7 @@ struct AsyncSocket { void AsyncSocketInitSocket(AsyncSocket *asock, AsyncSocketPollParams *params, const AsyncSocketVTable *vtable); +void AsyncSocketTeardownSocket(AsyncSocket *s); void AsyncSocketLock(AsyncSocket *asock); void AsyncSocketUnlock(AsyncSocket *asock); diff --git a/open-vm-tools/lib/asyncsocket/asyncSocketInterface.c b/open-vm-tools/lib/asyncsocket/asyncSocketInterface.c index 0d50b51cb..e4cd077fd 100644 --- a/open-vm-tools/lib/asyncsocket/asyncSocketInterface.c +++ b/open-vm-tools/lib/asyncsocket/asyncSocketInterface.c @@ -919,7 +919,7 @@ AsyncSocket_Close(AsyncSocket *asock) // IN if (VALID(asock, close)) { AsyncSocketLock(asock); ret = VT(asock)->close(asock); - AsyncSocketRelease(asock); + ASSERT(!asock->inited); AsyncSocketUnlock(asock); } else { ret = ASOCKERR_INVAL; diff --git a/open-vm-tools/lib/asyncsocket/asyncsocket.c b/open-vm-tools/lib/asyncsocket/asyncsocket.c index fa4613317..3c7ee8b49 100644 --- a/open-vm-tools/lib/asyncsocket/asyncsocket.c +++ b/open-vm-tools/lib/asyncsocket/asyncsocket.c @@ -4442,6 +4442,7 @@ AsyncTCPSocketClose(AsyncSocket *base) // IN } } + AsyncSocketTeardownSocket(base); return ASOCKERR_SUCCESS; } diff --git a/open-vm-tools/lib/file/file.c b/open-vm-tools/lib/file/file.c index 456af1f62..a34a9bb65 100644 --- a/open-vm-tools/lib/file/file.c +++ b/open-vm-tools/lib/file/file.c @@ -1603,6 +1603,10 @@ File_CreateDirectoryHierarchyEx(const char *pathName, // IN: while (TRUE) { Bool failed; char *temp; +#if defined(_WIN32) + DWORD status; + DWORD statusNew; +#endif index = FileFirstSlashIndex(pathName, index + 1); @@ -1617,17 +1621,36 @@ File_CreateDirectoryHierarchyEx(const char *pathName, // IN: * This is why we reverse the attempt and the check. */ + /* + * Bugfix 1592498, set last error "Access denied" instead of + * "File not found". File_XXX have different implementations on + * Windows and Linux, this problem only happens on Windows. + */ failed = !File_CreateDirectoryEx(temp, mask); +#if defined(_WIN32) + status = GetLastError(); + statusNew = ERROR_SUCCESS; +#endif if (failed) { if (File_IsDirectory(temp)) { failed = FALSE; + } else { +#if defined(_WIN32) + statusNew = GetLastError(); +#endif } } else if (topmostCreated != NULL && *topmostCreated == NULL) { *topmostCreated = temp; temp = NULL; } +#if defined(_WIN32) + if (status == ERROR_ACCESS_DENIED && statusNew == ERROR_FILE_NOT_FOUND) { + SetLastError(status); + } +#endif + free(temp); if (failed) { diff --git a/open-vm-tools/lib/include/productState.h b/open-vm-tools/lib/include/productState.h index d9463bb05..b93897d7c 100644 --- a/open-vm-tools/lib/include/productState.h +++ b/open-vm-tools/lib/include/productState.h @@ -51,7 +51,6 @@ typedef enum { PRODUCT_GANTRY = 1 << 9, PRODUCT_VMACORETESTS = 1 << 10, PRODUCT_SRM = 1 << 11, - PRODUCT_VIEWCRT = 1 << 12, /* etc */ } Product; typedef uint64 ProductMask;