Skip to content

Commit bfd47a8

Browse files
committed
another round of memory safety
1 parent 150271f commit bfd47a8

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/linenoise_stubs.c

+10-4
Original file line numberDiff line numberDiff line change
@@ -59,27 +59,33 @@ static void completion_bridge(const char *buf, linenoiseCompletions *lc)
5959
caml_release_runtime_system();
6060
}
6161

62-
static char *hints_bridge(const char *buf, int *color, int *bold)
62+
static char *hints_bridge_inner(const char *buf, int *color, int *bold)
6363
{
64-
caml_acquire_runtime_system();
6564
CAMLparam0();
6665
CAMLlocal2(str_copy, cb_result);
6766

6867
str_copy = caml_copy_string(buf);
6968

7069
cb_result = caml_callback(*caml_named_value("lnoise_hints_cb"), str_copy);
7170
if (cb_result == Val_none) {
72-
caml_release_runtime_system();
7371
CAMLreturnT(char *,NULL);
7472
} else {
7573
char* msg = caml_stat_strdup(String_val(Field(Field(cb_result, 0), 0)));
7674
*color = Int_val(Field(Field(cb_result, 0), 1)) + 31;
7775
*bold = Bool_val(Field(Field(cb_result, 0), 2));
78-
caml_release_runtime_system();
7976
CAMLreturnT(char *,msg);
8077
}
8178
}
8279

80+
static char *hints_bridge(const char *buf, int *color, int *bold)
81+
{
82+
caml_acquire_runtime_system();
83+
char* res = hints_bridge_inner(buf, color, bold);
84+
caml_release_runtime_system();
85+
return res;
86+
}
87+
88+
8389
static void free_hints_bridge(void* data) {
8490
caml_acquire_runtime_system();
8591
caml_stat_free(data);

0 commit comments

Comments
 (0)