From 850410ef9564b076a787b871fd6cf861d3dd37f5 Mon Sep 17 00:00:00 2001 From: ame Date: Sat, 20 Apr 2024 01:23:13 -0500 Subject: working on mem saftey --- src/lua.c | 8 +++++--- src/net.c | 27 +++++++++------------------ src/types/parray.h | 3 ++- 3 files changed, 16 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/lua.c b/src/lua.c index 395481f..22a5ef3 100644 --- a/src/lua.c +++ b/src/lua.c @@ -74,11 +74,13 @@ void i_dcopy(lua_State* src, lua_State* dest, void* _seen){ return; } + int *sp = malloc(sizeof * sp); + //lua_pushinteger(dest, 55); int r = luaL_ref(dest, LUA_REGISTRYINDEX); lua_rawgeti(dest, LUA_REGISTRYINDEX, r); - //*sp = r; - parray_set(seen, aauwu, (void*)&r); + *sp = r; + parray_set(seen, aauwu, sp); //printf("saved %i\n", *sp); //for(int i = 0; i != seen->len; i++){ @@ -126,7 +128,7 @@ void i_dcopy(lua_State* src, lua_State* dest, void* _seen){ lua_pushnil(dest); break; } - if(wnull) parray_clear(seen, NONE); + if(wnull) parray_clear(seen, FREE); //lua_settop(src, old_top); _seen = seen; } diff --git a/src/net.c b/src/net.c index 6b5df9b..fadad1c 100644 --- a/src/net.c +++ b/src/net.c @@ -714,7 +714,7 @@ int l_sendfile(lua_State* L){ str* r; i_write_header(L, header, &r, "", 0); send(client_fd, r->c, r->len, 0); - free(r); + str_free(r); char* buffer = calloc(sizeof* buffer, bsize + 1); FILE* fp = fopen(path, "rb"); @@ -819,7 +819,7 @@ void* handle_client(void *_arg){ int res_idx = lua_gettop(L); //handle cookies - if(sC != NULL){ + if(0 && sC != NULL){ lua_newtable(L); int lcookie = lua_gettop(L); @@ -893,7 +893,6 @@ void* handle_client(void *_arg){ //the function(s) //get all function that kinda match parray_t* owo = (parray_t*)v; - uint64_t passes = 0; for(int i = 0; i != owo->len; i++){ //though these are arrays of arrays we have to iterate *again* struct sarray_t* awa = (struct sarray_t*)owo->P[i].value; @@ -903,8 +902,6 @@ void* handle_client(void *_arg){ struct lchar* wowa = awa->cs[z]; if(strcmp(wowa->req, "all") == 0 || strcmp(wowa->req, sR->c) == 0 || (strcmp(sR->c, "HEAD") && strcmp(wowa->req, "GET"))){ - luaI_tseti(L, res_idx, "passes", passes); - passes++; luaL_loadbuffer(L, wowa->c, wowa->len, "fun"); @@ -1038,15 +1035,12 @@ int l_req_com(lua_State* L, char* req){ str* uwu = str_init(""); lua_pushvalue(L, 3); lua_dump(L, writer, (void*)uwu, 0); - lua_pushlstring(L, uwu->c, uwu->len); - str_free(uwu); - - size_t len; - char* a = (char*)luaL_checklstring(L, -1, &len); - awa = malloc(len + 1); - awa->c = a; - awa->len = len; + + awa = malloc(sizeof * awa); + awa->c = uwu->c; + awa->len = uwu->len; strcpy(awa->req, req); + free(uwu); //yes this *should* be str_free but awa kinda owns it now:p if(paths == NULL) paths = parray_init(); @@ -1057,11 +1051,11 @@ int l_req_com(lua_State* L, char* req){ if(v_old_paths == NULL){ old_paths = malloc(sizeof * old_paths); old_paths->len = 0; - old_paths->cs = malloc(sizeof * old_paths->cs); + old_paths->cs = malloc(sizeof old_paths->cs); } else old_paths = (struct sarray_t*)v_old_paths; old_paths->len++; - old_paths->cs = realloc(old_paths->cs, sizeof * old_paths->cs * old_paths->len); + old_paths->cs = realloc(old_paths->cs, sizeof old_paths->cs * old_paths->len); old_paths->cs[old_paths->len - 1] = awa; parray_set(paths, portss->c, (void*)old_paths); @@ -1096,9 +1090,6 @@ int l_unlock(lua_State* L){ } int l_listen(lua_State* L){ - lua_State* src = luaL_newstate(); - lua_State* dest = luaL_newstate(); - if(lua_gettop(L) != 2) { p_fatal("not enough args"); diff --git a/src/types/parray.h b/src/types/parray.h index bedadbf..fb89689 100644 --- a/src/types/parray.h +++ b/src/types/parray.h @@ -18,6 +18,7 @@ enum free_type { parray_t* parray_init(); void parray_set(parray_t*, char*, void*); +void parray_push(parray_t*, char*, void*); void* parray_get(parray_t* , char*); int parray_geti(parray_t* , char*); void parray_remove(parray_t* p, char* key, enum free_type free); @@ -26,4 +27,4 @@ void parray_lclear(parray_t*); parray_t* parray_find(parray_t*, char*); void free_method(void*, enum free_type); -#endif //parray_h \ No newline at end of file +#endif //parray_h -- cgit v1.2.3