Skip to content

Commit 2fe0f29

Browse files
committed
Minor improvement: avoid assuming that GetLastError value cannot be
affected by CloseHandle() or Sleep().
1 parent 1bbbcb0 commit 2fe0f29

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/backend/port/win32_shmem.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
77
*
88
* IDENTIFICATION
9-
* $PostgreSQL: pgsql/src/backend/port/win32_shmem.c,v 1.9 2009/05/05 09:48:51 mha Exp $
9+
* $PostgreSQL: pgsql/src/backend/port/win32_shmem.c,v 1.10 2009/05/05 21:51:46 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -158,23 +158,24 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
158158

159159
/*
160160
* If the segment already existed, CreateFileMapping() will return a
161-
* handle to the existing one.
161+
* handle to the existing one and set ERROR_ALREADY_EXISTS.
162162
*/
163163
if (GetLastError() == ERROR_ALREADY_EXISTS)
164164
{
165-
CloseHandle(hmap); /* Close the old handle, since we got a valid
165+
CloseHandle(hmap); /* Close the handle, since we got a valid
166166
* one to the previous segment. */
167+
hmap = NULL;
167168
Sleep(1000);
168169
continue;
169170
}
170171
break;
171172
}
172173

173174
/*
174-
* If the last call in the loop still returned ERROR_ALREADY_EXISTS, this shared memory
175-
* segment exists and we assume it belongs to somebody else.
175+
* If the last call in the loop still returned ERROR_ALREADY_EXISTS, this
176+
* shared memory segment exists and we assume it belongs to somebody else.
176177
*/
177-
if (GetLastError() == ERROR_ALREADY_EXISTS)
178+
if (!hmap)
178179
ereport(FATAL,
179180
(errmsg("pre-existing shared memory block is still in use"),
180181
errhint("Check if there are any old server processes still running, and terminate them.")));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy