summaryrefslogtreecommitdiff
path: root/otherlibs/systhreads/st_stubs.c
diff options
context:
space:
mode:
authorMax Mouratov <mmouratov@gmail.com>2014-05-29 05:11:47 +0600
committerMax Mouratov <mmouratov@gmail.com>2017-03-17 20:39:03 +0500
commit02a8b999f08dcbf6cfcdc1145f3286392d26ad52 (patch)
treea6d5a5f5566238184890c94efff644e9d8d2b4ae /otherlibs/systhreads/st_stubs.c
parent1a8af593ad2c179d2f30dede6f88f71be54f40c0 (diff)
downloadocaml-02a8b999f08dcbf6cfcdc1145f3286392d26ad52.tar.gz
runtime: replacing direct calls to malloc/calloc/realloc/free with calls to caml_stat_*
A few more wrappers were added (caml_stat_alloc_noexc, caml_stat_resize_noexc, caml_stat_calloc_noexc) that do not throw an exception in case of errors and offer a compatible substitute to the corresponding stdlib functions.
Diffstat (limited to 'otherlibs/systhreads/st_stubs.c')
-rw-r--r--otherlibs/systhreads/st_stubs.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/otherlibs/systhreads/st_stubs.c b/otherlibs/systhreads/st_stubs.c
index cd7daa7cfd..df3c7e7cf5 100644
--- a/otherlibs/systhreads/st_stubs.c
+++ b/otherlibs/systhreads/st_stubs.c
@@ -64,7 +64,7 @@ struct caml_thread_descr {
#define Start_closure(v) (((struct caml_thread_descr *)(v))->start_closure)
#define Terminated(v) (((struct caml_thread_descr *)(v))->terminated)
-/* The infos on threads (allocated via malloc()) */
+/* The infos on threads (allocated via caml_stat_alloc()) */
struct caml_thread_struct {
value descr; /* The heap-allocated descriptor (root) */
@@ -337,7 +337,7 @@ static uintnat caml_thread_stack_usage(void)
static caml_thread_t caml_thread_new_info(void)
{
caml_thread_t th;
- th = (caml_thread_t) malloc(sizeof(struct caml_thread_struct));
+ th = (caml_thread_t) caml_stat_alloc_noexc(sizeof(struct caml_thread_struct));
if (th == NULL) return NULL;
th->descr = Val_unit; /* filled later */
#ifdef NATIVE_CODE
@@ -410,7 +410,7 @@ static void caml_thread_remove_info(caml_thread_t th)
#ifndef NATIVE_CODE
caml_stat_free(th->stack_low);
#endif
- if (th->backtrace_buffer != NULL) free(th->backtrace_buffer);
+ if (th->backtrace_buffer != NULL) caml_stat_free(th->backtrace_buffer);
#ifndef WITH_SPACETIME
caml_stat_free(th);
/* CR-soon mshinwell: consider what to do about the Spacetime trace. Could
@@ -690,7 +690,7 @@ CAMLprim value caml_thread_uncaught_exception(value exn) /* ML */
char * msg = caml_format_exception(exn);
fprintf(stderr, "Thread %d killed on uncaught exception %s\n",
Int_val(Ident(curr_thread->descr)), msg);
- free(msg);
+ caml_stat_free(msg);
if (caml_backtrace_active) caml_print_exception_backtrace();
fflush(stderr);
return Val_unit;