aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoramelia squires <[email protected]>2025-09-27 04:11:49 -0500
committeramelia squires <[email protected]>2025-09-27 04:11:49 -0500
commite3a798740c2d64d0ac0dd4a08ebfec9d5a1c3cf8 (patch)
tree4fdf70facae0efe392a740438f15c85758c7f9c2
parent6acf870551b48679cc5c4d430502f1f8a719eafd (diff)
leaks and memory fixes
-rw-r--r--src/lua.c6
-rw-r--r--src/net/util.c10
-rw-r--r--src/thread.c11
-rw-r--r--src/types/map.c8
4 files changed, 26 insertions, 9 deletions
diff --git a/src/lua.c b/src/lua.c
index 2623e29..c51a906 100644
--- a/src/lua.c
+++ b/src/lua.c
@@ -51,7 +51,7 @@ int _stream_read(lua_State* L){
}
lua_pushlstring(L, cont->c, cont->len);
- free(cont);
+ str_free(cont);
return 1;
}
@@ -185,6 +185,9 @@ void luaI_deepcopy(lua_State* src, lua_State* dest, enum deep_copy_flags flags){
case LUA_TBOOLEAN:
lua_pushboolean(dest, lua_toboolean(src, -1));
break;
+ case LUA_TNIL:
+ lua_pushnil(dest);
+ break;
case LUA_TSTRING:;
size_t slen;
const char* ss = lua_tolstring(src, -1, &slen);
@@ -403,6 +406,7 @@ void luaI_copyvars(lua_State* from, lua_State* to){
env_table(from, x != 0);
luaI_deepcopy(from, to, SKIP_GC | SKIP_LOCALS);
+ lua_pop(from, 1);
int idx = lua_gettop(to);
lua_pushglobaltable(to);
int tidx = lua_gettop(to);
diff --git a/src/net/util.c b/src/net/util.c
index 78e3043..61cf1b7 100644
--- a/src/net/util.c
+++ b/src/net/util.c
@@ -341,7 +341,7 @@ int match_param(char* path, char* match, parray_t* arr){
case GET_KEY:
if(path[pi] == '}'){
step = GET_VALUE;
- name = calloc(pi - start, sizeof * name);
+ name = calloc(pi - start + 1, sizeof * name);
memcpy(name, path + start + 1, pi - start - 1);
start = mi;
}
@@ -352,7 +352,7 @@ int match_param(char* path, char* match, parray_t* arr){
if(match[mi] == '/'){
step = NORMAL;
- char* out = calloc(mi - start, sizeof * out);
+ char* out = calloc(mi - start + 1, sizeof * out);
memcpy(out, match + start, mi - start);
parray_set(arr, name, out);
free(name);
@@ -410,6 +410,7 @@ uint64_t _mimetypes_len = 15;
void parse_mimetypes(){
if(_mimetypes == NULL || _mimetypes_len == 0) return;
+ if(mime_type != NULL) return;
mime_type = map_init();
FILE* fp = fopen(_mimetypes, "r");
@@ -436,9 +437,10 @@ void parse_mimetypes(){
if(line[i] == ' ' || line[i] == '\t' || line[i] == '\n'){
if(type_len == 0) continue;
char* mtype_c = calloc(1024, sizeof * mtype);
- strcpy(mtype_c, mtype);
+ mtype_c = strcpy(mtype_c, mtype);
map_set(&mime_type, type, mtype_c);
type_len = 0;
+ free(type);
type = calloc(512, sizeof * type);
} else {
type[type_len] = line[i];
@@ -449,10 +451,12 @@ void parse_mimetypes(){
free(type);
}
+ free(line);
fclose(fp);
}
void _parse_mimetypes(){
+ abort();
mime_type = map_init();
FILE* fp = fopen(MIMETYPES, "r");
char* buffer = calloc(1024, sizeof * buffer);
diff --git a/src/thread.c b/src/thread.c
index bb412ba..48ddba1 100644
--- a/src/thread.c
+++ b/src/thread.c
@@ -232,6 +232,9 @@ int _thread_await(lua_State* L){
lua_settop(info->L, ot);
}
+ lua_pushnil(L);
+ lua_setglobal(L, "_locals");
+
return info->return_count;
}
@@ -492,9 +495,11 @@ int l_buffer(lua_State* L){
luaI_tsetcf(L, meta_idx, "__index", l_buffer_index);
luaI_tsetcf(L, meta_idx, "__gc", l_buffer_gc);
- lua_getmetatable(L, 1);
- int idx = lua_gettop(L);
- luaI_tsetnil(L, idx, "__gc");
+ if(use != 0){
+ lua_getmetatable(L, 1);
+ int idx = lua_gettop(L);
+ luaI_tsetnil(L, idx, "__gc");
+ }
lua_pushvalue(L, meta_idx);
lua_setmetatable(L, buffer_idx);
diff --git a/src/types/map.c b/src/types/map.c
index abf075c..80e072c 100644
--- a/src/types/map.c
+++ b/src/types/map.c
@@ -32,15 +32,19 @@ map_t* map_init(){
return map_initl(4);
}
+//TODO: make this better:3
void map_expand(map_t** _M){
map_t* M = *_M;
map_t* remade = map_initl(M->mod * 4);
for(int i = 0; i != M->mod; i++){
//what happens if the map_set calls map_regraph??? idk
- if(M->M[i].used)
- map_set(&remade, M->M[i].key->c, M->M[i].value);
+ if(M->M[i].used){
+ map_set(&remade, M->M[i].key->c, M->M[i].value);
+ str_free(M->M[i].key);
+ }
}
+ map_lclear(M);
*_M = remade;
}