fix a bunch of small memory leaks around REPLXX

not that they'd cause any problems in practice - they're very small, and are in the one context where GC can actually run
This commit is contained in:
dzaima 2022-12-24 16:42:42 +02:00
parent e2c21f6103
commit 24dba9ba40

View File

@ -289,10 +289,11 @@ static bool isCmd(char* s, char** e, const char* cmd) {
void hint_replxx(const char* inp, replxx_hints* res, int* dist, ReplxxColor* c, void* data) {
completion_impl(inp, res, true, dist);
}
static NOINLINE char* malloc_B(B x) { // toCStr but allocated by malloc
static NOINLINE char* malloc_B(B x) { // toCStr but allocated by malloc; frees x
u64 len1 = utf8lenB(x);
char* s1 = malloc(len1+1);
toUTF8(x, s1);
decG(x);
s1[len1] = '\0';
return s1;
}
@ -305,7 +306,7 @@ static bool isCmd(char* s, char** e, const char* cmd) {
replxx_get_state(global_replxx, &st);
return (TmpState){.s = utf8Decode0(st.text), .pos = st.cursorPosition};
}
static NOINLINE void setState(TmpState s) {
static NOINLINE void setState(TmpState s) { // frees s.s
char* r = malloc_B(s.s);
ReplxxState st = (ReplxxState){.text = r, .cursorPosition = s.pos};
replxx_set_state(global_replxx, &st);
@ -428,7 +429,9 @@ static bool isCmd(char* s, char** e, const char* cmd) {
char* s = toCStr(ln); char* e;
if (isCmd(s, &e, "theme=" )) cfg_theme = e[0]-'0';
else if (isCmd(s, &e, "keyboard=")) cfg_enableKeyboard = e[0]-'0';
freeCStr(s);
}
decG(lns);
cfg_set_theme(cfg_theme, false);
cfg_set_keyboard(cfg_enableKeyboard, false);
}