diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2021-11-13 17:46:08 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2021-11-13 17:46:08 -0800 |
commit | 12b2a44cf6413ef0c51c4e13af1c03369f9e803f (patch) | |
tree | 74126521afd4a7ab4320910f6886da6d5c156bc9 /src | |
parent | 398112f756f2944df6165a9e9c81c9e62618f3bf (diff) | |
download | teliva-12b2a44cf6413ef0c51c4e13af1c03369f9e803f.tar.gz |
stop leaking memory
Diffstat (limited to 'src')
-rw-r--r-- | src/kilo.c | 5 | ||||
-rw-r--r-- | src/lua.c | 5 |
2 files changed, 6 insertions, 4 deletions
diff --git a/src/kilo.c b/src/kilo.c index 7ea4dd0..402ffcb 100644 --- a/src/kilo.c +++ b/src/kilo.c @@ -1172,8 +1172,9 @@ static void editorMoveCursor(int key) { extern void save_to_current_definition_and_editor_buffer(lua_State *L, char *name); extern void load_editor_buffer_to_current_definition_in_image(lua_State *L); extern void editorRefreshBuffer(void); +#define CURRENT_DEFINITION_LEN 256 static void editorGo(lua_State* L, int fd) { - char query[KILO_QUERY_LEN+1] = {0}; + char query[CURRENT_DEFINITION_LEN+1] = {0}; int qlen = 0; editorSaveToDisk(); @@ -1194,7 +1195,7 @@ static void editorGo(lua_State* L, int fd) { } return; } else if (isprint(c)) { - if (qlen < KILO_QUERY_LEN) { + if (qlen < CURRENT_DEFINITION_LEN) { query[qlen++] = c; query[qlen] = '\0'; } diff --git a/src/lua.c b/src/lua.c index 8796ca7..f226828 100644 --- a/src/lua.c +++ b/src/lua.c @@ -304,9 +304,10 @@ static int handle_image (lua_State *L, char **argv, int n) { } -const char *Current_definition = NULL; +#define CURRENT_DEFINITION_LEN 256 +char Current_definition[CURRENT_DEFINITION_LEN+1] = {0}; void save_to_current_definition_and_editor_buffer (lua_State *L, const char *definition) { - Current_definition = strdup(definition); + strncpy(Current_definition, definition, CURRENT_DEFINITION_LEN); lua_getglobal(L, "teliva_program"); lua_getfield(L, -1, Current_definition); const char *contents = lua_tostring(L, -1); |