Call obj_free for T_DATA, T_FILE objects on exit
Previously, T_DATA and T_FILE objects did not have their instance variables freed on exit which would be reported as a memory leak with RUBY_FREE_ON_EXIT. This commit changes it to use obj_free which also frees the generic instance variables. Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
This commit is contained in:
parent
e3631277c3
commit
912016f626
22
gc.c
22
gc.c
@ -4565,6 +4565,12 @@ gc_abort(rb_objspace_t *objspace)
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < SIZE_POOL_COUNT; i++) {
|
||||
rb_size_pool_t *size_pool = &size_pools[i];
|
||||
rb_heap_t *heap = SIZE_POOL_EDEN_HEAP(size_pool);
|
||||
rgengc_mark_and_rememberset_clear(objspace, heap);
|
||||
}
|
||||
|
||||
gc_mode_set(objspace, gc_mode_none);
|
||||
}
|
||||
|
||||
@ -4602,7 +4608,7 @@ rb_objspace_free_objects(rb_objspace_t *objspace)
|
||||
switch (BUILTIN_TYPE(vp)) {
|
||||
case T_DATA: {
|
||||
if (rb_obj_is_mutex(vp) || rb_obj_is_thread(vp)) {
|
||||
rb_data_free(objspace, vp);
|
||||
obj_free(objspace, vp);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -4651,14 +4657,6 @@ rb_objspace_call_finalizer(rb_objspace_t *objspace)
|
||||
/* Abort incremental marking and lazy sweeping to speed up shutdown. */
|
||||
gc_abort(objspace);
|
||||
|
||||
if (rb_free_on_exit) {
|
||||
for (int i = 0; i < SIZE_POOL_COUNT; i++) {
|
||||
rb_size_pool_t *size_pool = &size_pools[i];
|
||||
rb_heap_t *heap = SIZE_POOL_EDEN_HEAP(size_pool);
|
||||
rgengc_mark_and_rememberset_clear(objspace, heap);
|
||||
}
|
||||
}
|
||||
|
||||
/* prohibit GC because force T_DATA finalizers can break an object graph consistency */
|
||||
dont_gc_on();
|
||||
|
||||
@ -4684,12 +4682,10 @@ rb_objspace_call_finalizer(rb_objspace_t *objspace)
|
||||
if (rb_obj_is_fiber(vp)) break;
|
||||
if (rb_obj_is_main_ractor(vp)) break;
|
||||
|
||||
rb_data_free(objspace, vp);
|
||||
obj_free(objspace, vp);
|
||||
break;
|
||||
case T_FILE:
|
||||
if (RANY(p)->as.file.fptr) {
|
||||
make_io_zombie(objspace, vp);
|
||||
}
|
||||
obj_free(objspace, vp);
|
||||
break;
|
||||
case T_SYMBOL:
|
||||
case T_ARRAY:
|
||||
|
Loading…
x
Reference in New Issue
Block a user