Skip to content

Commit 1ad3768

Browse files
Add a null check before invoking finalizer. Before, we would do a callvirt Finalize() on the object and if it didn't have a finalizer, it would call Object::Finalize(). However, since now we use mono_method_invoke with a concrete method, we crash if it's null. So we just
1 parent 4768280 commit 1ad3768

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

mono/metadata/gc.c

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -327,14 +327,6 @@ mono_gc_run_finalize (void *obj, void *data)
327327
return;
328328
}
329329

330-
/*
331-
* To avoid the locking plus the other overhead of mono_runtime_invoke_checked (),
332-
* create and precompile a wrapper which calls the finalize method using
333-
* a CALLVIRT.
334-
*/
335-
if (log_finalizers)
336-
g_log ("mono-gc-finalizers", G_LOG_LEVEL_MESSAGE, "<%s at %p> Compiling finalizer.", o->vtable->klass->name, o);
337-
338330
mono_runtime_class_init_full (o->vtable, &error);
339331
goto_if_nok (&error, unhandled_error);
340332

@@ -343,18 +335,20 @@ mono_gc_run_finalize (void *obj, void *data)
343335
o->vtable->klass->name_space, o->vtable->klass->name);
344336
}
345337

346-
if (log_finalizers)
347-
g_log ("mono-gc-finalizers", G_LOG_LEVEL_MESSAGE, "<%s at %p> Calling finalizer.", o->vtable->klass->name, o);
338+
if (finalizer) {
339+
if (log_finalizers)
340+
g_log ("mono-gc-finalizers", G_LOG_LEVEL_MESSAGE, "<%s at %p> Calling finalizer.", o->vtable->klass->name, o);
348341

349-
MONO_PROFILER_RAISE (gc_finalizing_object, (o));
342+
MONO_PROFILER_RAISE (gc_finalizing_object, (o));
350343

351-
gpointer params[] = { NULL };
352-
mono_runtime_try_invoke (finalizer, o, params, &exc, &error);
344+
gpointer params[] = { NULL };
345+
mono_runtime_try_invoke (finalizer, o, params, &exc, &error);
353346

354-
MONO_PROFILER_RAISE (gc_finalized_object, (o));
347+
MONO_PROFILER_RAISE (gc_finalized_object, (o));
355348

356-
if (log_finalizers)
357-
g_log ("mono-gc-finalizers", G_LOG_LEVEL_MESSAGE, "<%s at %p> Returned from finalizer.", o->vtable->klass->name, o);
349+
if (log_finalizers)
350+
g_log ("mono-gc-finalizers", G_LOG_LEVEL_MESSAGE, "<%s at %p> Returned from finalizer.", o->vtable->klass->name, o);
351+
}
358352

359353
unhandled_error:
360354
if (!is_ok (&error))

0 commit comments

Comments
 (0)