diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2021-11-13 17:42:39 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2021-11-13 17:42:39 -0800 |
commit | 398112f756f2944df6165a9e9c81c9e62618f3bf (patch) | |
tree | 5325b7bfe4cbfa3860bdcf59494d8a31b7c0bb00 | |
parent | 51378afb2a8276020386a18d5572958fff157bdc (diff) | |
download | teliva-398112f756f2944df6165a9e9c81c9e62618f3bf.tar.gz |
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.
-rw-r--r-- | src/lua.c | 4 |
1 files changed, 3 insertions, 1 deletions
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 <assert.h> #include <fcntl.h> #include <locale.h> #include <ncurses.h> @@ -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); } |