summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2009-05-05 21:51:46 +0000
committerTom Lane2009-05-05 21:51:46 +0000
commit26fe3964b4273460d41cac9481b83de657cac733 (patch)
tree25ce4dc3039b03f55ff7a35370d98672d3bd76be
parent0d31fb6d1a5f95f27884a25c1d72503730918152 (diff)
Minor improvement: avoid assuming that GetLastError value cannot be
affected by CloseHandle() or Sleep().
-rw-r--r--src/backend/port/win32_shmem.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/backend/port/win32_shmem.c b/src/backend/port/win32_shmem.c
index 05c35eb009..c177d008d8 100644
--- a/src/backend/port/win32_shmem.c
+++ b/src/backend/port/win32_shmem.c
@@ -158,12 +158,13 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
/*
* If the segment already existed, CreateFileMapping() will return a
- * handle to the existing one.
+ * handle to the existing one and set ERROR_ALREADY_EXISTS.
*/
if (GetLastError() == ERROR_ALREADY_EXISTS)
{
- CloseHandle(hmap); /* Close the old handle, since we got a valid
+ CloseHandle(hmap); /* Close the handle, since we got a valid
* one to the previous segment. */
+ hmap = NULL;
Sleep(1000);
continue;
}
@@ -171,10 +172,10 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
}
/*
- * If the last call in the loop still returned ERROR_ALREADY_EXISTS, this shared memory
- * segment exists and we assume it belongs to somebody else.
+ * If the last call in the loop still returned ERROR_ALREADY_EXISTS, this
+ * shared memory segment exists and we assume it belongs to somebody else.
*/
- if (GetLastError() == ERROR_ALREADY_EXISTS)
+ if (!hmap)
ereport(FATAL,
(errmsg("pre-existing shared memory block is still in use"),
errhint("Check if there are any old server processes still running, and terminate them.")));