postgres.git / summary / log / commit / refs

commit    b1c44848ce36d892948b9b014e4c1e49f77dc82b
Author:   Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date:     Thu Oct 15 09:04:27 2026 +0000
First released in: 14.25, 15.20, 16.16, 17.12, 18.7, 19.0

    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


src/backend/port/win32/timer.c | 2 +- src/bin/pg_test_fsync/pg_test_fsync.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/backend/port/win32/timer.c b/src/backend/port/win32/timer.c index 53fdae9468b..d7465ebfcbf 100644 --- a/src/backend/port/win32/timer.c +++ b/src/backend/port/win32/timer.c @@ -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()))); diff --git a/src/bin/pg_test_fsync/pg_test_fsync.c b/src/bin/pg_test_fsync/pg_test_fsync.c index 78dab5096c6..ea810815be7 100644 --- a/src/bin/pg_test_fsync/pg_test_fsync.c +++ b/src/bin/pg_test_fsync/pg_test_fsync.c @@ -44,8 +44,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_log_error("could not create thread for alarm"); \ exit(1); \ [parent: 623cdfa6493d]