diff --git a/ext/dl/cfunc.c b/ext/dl/cfunc.c index 66aebf2e79273e..ddef51e727ed1e 100644 --- a/ext/dl/cfunc.c +++ b/ext/dl/cfunc.c @@ -3,6 +3,7 @@ */ #include +#include #include #include "dl.h" diff --git a/ext/syslog/syslog.c b/ext/syslog/syslog.c index 02f36aaf25dec9..f4c45dfbe45362 100644 --- a/ext/syslog/syslog.c +++ b/ext/syslog/syslog.c @@ -49,7 +49,7 @@ static VALUE mSyslog_close(VALUE self) closelog(); - free((void *)syslog_ident); + xfree((void *)syslog_ident); syslog_ident = NULL; syslog_options = syslog_facility = syslog_mask = -1; syslog_opened = 0; diff --git a/gc.c b/gc.c index aa9976f715cfc8..c360c61f3e1bc6 100644 --- a/gc.c +++ b/gc.c @@ -932,6 +932,23 @@ ruby_xfree(void *x) vm_xfree(&rb_objspace, x); } +/* Mimic ruby_xmalloc, but need not rb_objspace. + * should return pointer suitable for ruby_xfree + */ +void * +ruby_mimmalloc(size_t size) +{ + void *mem; +#if CALC_EXACT_MALLOC_SIZE + size += sizeof(size_t); +#endif + mem = malloc(size); +#if CALC_EXACT_MALLOC_SIZE + ((size_t *)mem)[0] = size; + mem = (size_t *)mem + 1; +#endif + return mem; +} /* * call-seq: diff --git a/internal.h b/internal.h index cf3fec20b5946a..4c476ec9d0508d 100644 --- a/internal.h +++ b/internal.h @@ -93,6 +93,7 @@ void Init_File(void); /* gc.c */ void Init_heap(void); +void *ruby_mimmalloc(size_t size); /* inits.c */ void rb_call_inits(void); diff --git a/vm.c b/vm.c index f029d4584c57c3..90f7e3e5198b1e 100644 --- a/vm.c +++ b/vm.c @@ -1620,7 +1620,7 @@ ruby_vm_destruct(rb_vm_t *vm) #endif ruby_vm_run_at_exit_hooks(vm); rb_vm_gvl_destroy(vm); - free(vm); + ruby_xfree(vm); ruby_current_vm = 0; } RUBY_FREE_LEAVE("vm"); @@ -1795,7 +1795,7 @@ thread_free(void *ptr) free(th->altstack); } #endif - free(ptr); + ruby_xfree(ptr); } if (ruby_current_thread == th) ruby_current_thread = NULL; @@ -2198,8 +2198,8 @@ void Init_BareVM(void) { /* VM bootstrap: phase 1 */ - rb_vm_t * vm = malloc(sizeof(*vm)); - rb_thread_t * th = malloc(sizeof(*th)); + rb_vm_t * vm = ruby_mimmalloc(sizeof(*vm)); + rb_thread_t * th = ruby_mimmalloc(sizeof(*th)); if (!vm || !th) { fprintf(stderr, "[FATAL] failed to allocate memory\n"); exit(EXIT_FAILURE);