From 398112f756f2944df6165a9e9c81c9e62618f3bf Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 13 Nov 2021 17:42:39 -0800 Subject: memory corruption bug I was saving an address on the stack to a global, and it was getting clobbered later. This is the sort of thing I completely eliminated in https://github.com/akkartik/mu :/ Now I'm taking a leaf out of the Mu playbook and leaking a little bit of memory every time I switch definitions. --- src/lua.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/lua.c') diff --git a/src/lua.c b/src/lua.c index 337341d..8796ca7 100644 --- a/src/lua.c +++ b/src/lua.c @@ -5,6 +5,7 @@ */ +#include #include #include #include @@ -305,7 +306,7 @@ static int handle_image (lua_State *L, char **argv, int n) { const char *Current_definition = NULL; void save_to_current_definition_and_editor_buffer (lua_State *L, const char *definition) { - Current_definition = definition; + Current_definition = strdup(definition); lua_getglobal(L, "teliva_program"); lua_getfield(L, -1, Current_definition); const char *contents = lua_tostring(L, -1); @@ -327,6 +328,7 @@ static void read_contents (lua_State *L, char *filename, char *out) { /* table to update is at top of stack */ static void update_definition (lua_State *L, const char *name, char *out) { lua_pushstring(L, out); + assert(strlen(name) > 0); lua_setfield(L, -2, name); } -- cgit 1.4.1-2-gfad0