1
0
mirror of https://github.com/postgres/postgres.git synced 2026-10-23 13:29:09 +03:00

Fix CreateThread() failure checks

CreateThread returns NULL on failure, not INVALID_HANDLE_VALUE.  In
setitimer(), a failed thread creation would silently disable all
timer-based timeouts.

Author: Sehrope Sarkuni <sehrope@jackdb.com>
Discussion: https://www.postgresql.org/message-id/CAH7T-apWWfEt+V8uLU7KXv7CMM9LoqJ1Zo2LdWmXMz=u-Ek9=w@mail.gmail.com
Backpatch-through: 14
This commit is contained in:
Heikki Linnakangas
2026-10-15 12:04:27 +03:00
parent 7cafc4abbd
commit 908589bdbd
2 changed files with 2 additions and 3 deletions

View File

@@ -103,7 +103,7 @@ setitimer(int which, const struct itimerval *value, struct itimerval *ovalue)
InitializeCriticalSection(&timerCommArea.crit_sec);
timerThreadHandle = CreateThread(NULL, 0, pg_timer_thread, NULL, 0, NULL);
if (timerThreadHandle == INVALID_HANDLE_VALUE)
if (timerThreadHandle == NULL)
ereport(FATAL,
(errmsg_internal("could not create timer thread: error code %lu",
GetLastError())));

View File

@@ -45,8 +45,7 @@ do { \
#define START_TIMER \
do { \
alarm_triggered = false; \
if (CreateThread(NULL, 0, process_alarm, NULL, 0, NULL) == \
INVALID_HANDLE_VALUE) \
if (CreateThread(NULL, 0, process_alarm, NULL, 0, NULL) == NULL) \
pg_fatal("could not create thread for alarm"); \
gettimeofday(&start_t, NULL); \
} while (0)