Thread (6 messages) 6 messages, 2 authors, 2023-02-01
STALE1240d

[PATCH v2] win32: check for NULL after creating thread

From: Rose via GitGitGadget <hidden>
Date: 2023-01-31 14:53:49
Subsystem: the rest · Maintainer: Linus Torvalds

From: Seija Kijin <redacted>

Check for NULL handles, not "INVALID_HANDLE,"
as CreateThread guarantees a valid handle in most cases.

The return value for failed thread creation is NULL,
not INVALID_HANDLE_VALUE, unlike other Windows
API functions.

Signed-off-by: Seija Kijin <redacted>
---
    win32: check for NULL after creating thread
    
    Check for NULL handles, not "INVALID_HANDLE," as CreateThread guarantees
    a valid handle in most cases.
    
    The return value for failed thread creation is NULL, not
    INVALID_HANDLE_VALUE, unlike other Windows API functions.
    
    Signed-off-by: Seija Kijin doremylover123@gmail.com

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1445%2FAtariDreams%2FhThread-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1445/AtariDreams/hThread-v2
Pull-Request: https://github.com/git/git/pull/1445

Range-diff vs v1:

 1:  e75d15e42f4 ! 1:  c956cafdec9 win32: check for NULL when creating thread
     @@ Metadata
      Author: Seija Kijin [off-list ref]
      
       ## Commit message ##
     -    win32: check for NULL when creating thread
     +    win32: check for NULL after creating thread
      
          Check for NULL handles, not "INVALID_HANDLE,"
          as CreateThread guarantees a valid handle in most cases.


 compat/winansi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/compat/winansi.c b/compat/winansi.c
index 3abe8dd5a27..f83610f684d 100644
--- a/compat/winansi.c
+++ b/compat/winansi.c
@@ -644,7 +644,7 @@ void winansi_init(void)
 
 	/* start console spool thread on the pipe's read end */
 	hthread = CreateThread(NULL, 0, console_thread, NULL, 0, NULL);
-	if (hthread == INVALID_HANDLE_VALUE)
+	if (!hthread)
 		die_lasterr("CreateThread(console_thread) failed");
 
 	/* schedule cleanup routine */
base-commit: 2fc9e9ca3c7505bc60069f11e7ef09b1aeeee473
-- 
gitgitgadget
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help