aboutsummaryrefslogtreecommitdiffstats
path: root/gc.c
diff options
context:
space:
mode:
authorUrabe, Shyouhei <shyouhei@ruby-lang.org>2019-04-26 18:59:26 +0900
committerUrabe, Shyouhei <shyouhei@ruby-lang.org>2019-04-29 21:52:44 +0900
commitf95f07dad30a80b7e3eb4b2838ca4311d2822764 (patch)
tree8429bf10ff496c05aff318ee48cc19279777b4f5 /gc.c
parent34e1079aef81d108890fb167d7df69960e994ff5 (diff)
downloadruby-f95f07dad30a80b7e3eb4b2838ca4311d2822764.tar.gz
avoid passing NULL to memset
`GC::Profiler.enable; GC::Profiler.clear` tries to clear objspace->profile.records but it has never been allocated before. Thus the MEMCPY took NULL argument before this changeset. The objspace->profile.records is allocated appropriately elsewhere. Why not juts free it if any? That should work.
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/gc.c b/gc.c
index f1715de7b7..cf3bb3fac2 100644
--- a/gc.c
+++ b/gc.c
@@ -10476,16 +10476,14 @@ static VALUE
gc_profile_clear(void)
{
rb_objspace_t *objspace = &rb_objspace;
- if (GC_PROFILE_RECORD_DEFAULT_SIZE * 2 < objspace->profile.size) {
- objspace->profile.size = GC_PROFILE_RECORD_DEFAULT_SIZE * 2;
- objspace->profile.records = realloc(objspace->profile.records, sizeof(gc_profile_record) * objspace->profile.size);
- if (!objspace->profile.records) {
- rb_memerror();
- }
- }
- MEMZERO(objspace->profile.records, gc_profile_record, objspace->profile.size);
+ void *p = objspace->profile.records;
+ objspace->profile.records = NULL;
+ objspace->profile.size = 0;
objspace->profile.next_index = 0;
objspace->profile.current_record = 0;
+ if (p) {
+ free(p);
+ }
return Qnil;
}