All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Rose via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Johannes Sixt <j6t@kdbg.org>,
	Rose <83477269+AtariDreams@users.noreply.github.com>,
	Seija Kijin <doremylover123@gmail.com>
Subject: [PATCH v2] win32: use _endthreadex to terminate threads, not ExitThread
Date: Sun, 25 Dec 2022 01:41:50 +0000	[thread overview]
Message-ID: <pull.1414.v2.git.git.1671932510529.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1414.git.git.1671742750504.gitgitgadget@gmail.com>

From: Seija Kijin <doremylover123@gmail.com>

Because we use the C runtime and
use _beginthreadex to create pthreads,
pthread_exit MUST use _endthreadex.

Otherwise, according to Microsoft:
"Failure to do so results in small
memory leaks when the thread
calls ExitThread."

Simply put, this is not the same as ExitThread.

Signed-off-by: Seija Kijin <doremylover123@gmail.com>
---
    win32: use _endthreadex to terminate threads, not ExitThread
    
    Because we use the C runtime and use _beginthread to create pthreads,
    pthread_exit MUST use _endthread.
    
    Otherwise, according to Microsoft: "Failure to do so results in small
    memory leaks when the thread calls ExitThread."
    
    Simply put, this is not the same as ExitThread.
    
    Signed-off-by: Seija Kijin doremylover123@gmail.com

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1414%2FAtariDreams%2Fsevere-bug-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1414/AtariDreams/severe-bug-v2
Pull-Request: https://github.com/git/git/pull/1414

Range-diff vs v1:

 1:  78f9d54c304 ! 1:  3e8212fb9a7 win32: use _endthreadex to terminate threads, not ExitThread
     @@ Metadata
       ## Commit message ##
          win32: use _endthreadex to terminate threads, not ExitThread
      
     -    This is a pretty serious bug actually:
          Because we use the C runtime and
          use _beginthreadex to create pthreads,
          pthread_exit MUST use _endthreadex.


 compat/win32/pthread.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/compat/win32/pthread.h b/compat/win32/pthread.h
index 737983d00ba..cc3221cb2c8 100644
--- a/compat/win32/pthread.h
+++ b/compat/win32/pthread.h
@@ -66,7 +66,7 @@ pthread_t pthread_self(void);
 
 static inline void NORETURN pthread_exit(void *ret)
 {
-	ExitThread((DWORD)(intptr_t)ret);
+	_endthreadex((unsigned)(uintptr_t)ret);
 }
 
 typedef DWORD pthread_key_t;

base-commit: 7c2ef319c52c4997256f5807564523dfd4acdfc7
-- 
gitgitgadget

  parent reply	other threads:[~2022-12-25  1:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-22 20:59 [PATCH] win32: use _endthreadex to terminate threads, not ExitThread Rose via GitGitGadget
2022-12-24  8:01 ` Johannes Sixt
2022-12-25  1:41 ` Rose via GitGitGadget [this message]
2022-12-25  8:54   ` [PATCH v2] " Johannes Sixt
2022-12-25 12:40     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=pull.1414.v2.git.git.1671932510529.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=83477269+AtariDreams@users.noreply.github.com \
    --cc=doremylover123@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=j6t@kdbg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.