From bfd47a8d4c2cec48934a2ec5694e4371668d0eb9 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Thu, 7 Mar 2024 15:11:37 -0500 Subject: [PATCH] another round of memory safety --- src/linenoise_stubs.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/linenoise_stubs.c b/src/linenoise_stubs.c index 28d2bbc..0f4b9bd 100644 --- a/src/linenoise_stubs.c +++ b/src/linenoise_stubs.c @@ -59,9 +59,8 @@ static void completion_bridge(const char *buf, linenoiseCompletions *lc) caml_release_runtime_system(); } -static char *hints_bridge(const char *buf, int *color, int *bold) +static char *hints_bridge_inner(const char *buf, int *color, int *bold) { - caml_acquire_runtime_system(); CAMLparam0(); CAMLlocal2(str_copy, cb_result); @@ -69,17 +68,24 @@ static char *hints_bridge(const char *buf, int *color, int *bold) cb_result = caml_callback(*caml_named_value("lnoise_hints_cb"), str_copy); if (cb_result == Val_none) { - caml_release_runtime_system(); CAMLreturnT(char *,NULL); } else { char* msg = caml_stat_strdup(String_val(Field(Field(cb_result, 0), 0))); *color = Int_val(Field(Field(cb_result, 0), 1)) + 31; *bold = Bool_val(Field(Field(cb_result, 0), 2)); - caml_release_runtime_system(); CAMLreturnT(char *,msg); } } +static char *hints_bridge(const char *buf, int *color, int *bold) +{ + caml_acquire_runtime_system(); + char* res = hints_bridge_inner(buf, color, bold); + caml_release_runtime_system(); + return res; +} + + static void free_hints_bridge(void* data) { caml_acquire_runtime_system(); caml_stat_free(data);