Skip to content

Commit

Permalink
Fix null dereference in check_finalizer_nested if redirect malloc on …
Browse files Browse the repository at this point in the history
…Linux

(fix of commit 644cf3c)

Issue #582 (bdwgc).

As noted in GC_pthread_start, an allocation may happen in
GC_get_stack_base, causing GC_notify_or_invoke_finalizers to be called
before the thread gets registered.

* pthread_support.c [!GC_NO_FINALIZATION] (GC_check_finalizer_nested):
Define me local variable.
* pthread_support.c [!GC_NO_FINALIZATION && INCLUDE_LINUX_THREAD_DESCR
&& REDIRECT_MALLOC] (GC_check_finalizer_nested): If me variable is NULL
then return NULL; add comment.
  • Loading branch information
ivmai committed Dec 9, 2023
1 parent cdb34cd commit 0408c6e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pthread_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -880,11 +880,19 @@ STATIC GC_thread GC_self_thread(void) {
/* Called by GC_notify_or_invoke_finalizers() only. */
GC_INNER unsigned char *GC_check_finalizer_nested(void)
{
GC_thread me;
GC_stack_context_t crtn;
unsigned nesting_level;

GC_ASSERT(I_HOLD_LOCK());
crtn = GC_self_thread_inner() -> crtn;
me = GC_self_thread_inner();
# if defined(INCLUDE_LINUX_THREAD_DESCR) && defined(REDIRECT_MALLOC)
/* As noted in GC_pthread_start, an allocation may happen in */
/* GC_get_stack_base, causing GC_notify_or_invoke_finalizers */
/* to be called before the thread gets registered. */
if (EXPECT(NULL == me, FALSE)) return NULL;
# endif
crtn = me -> crtn;
nesting_level = crtn -> finalizer_nested;
if (nesting_level) {
/* We are inside another GC_invoke_finalizers(). */
Expand Down

0 comments on commit 0408c6e

Please sign in to comment.