From 0b28025b0b69266905a9f6235c7476bb799eea37 Mon Sep 17 00:00:00 2001 From: ame Date: Tue, 13 Feb 2024 14:14:20 -0600 Subject: idk --- src/i_str.c | 1 + src/i_util.c | 1 + src/lua.c | 23 ++++++++++++++--------- src/lua.h | 4 ++++ src/net.c | 6 ++++-- src/parray.c | 1 + 6 files changed, 25 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/i_str.c b/src/i_str.c index 5b12a3f..d77067b 100644 --- a/src/i_str.c +++ b/src/i_str.c @@ -1,4 +1,5 @@ #include "i_str.h" +#include "lua.h" str* str_init(char* init){ if(init == NULL){ diff --git a/src/i_util.c b/src/i_util.c index 0a20224..48749d7 100644 --- a/src/i_util.c +++ b/src/i_util.c @@ -2,6 +2,7 @@ #include #include #include "lua.h" + void p_fatal(const char* m){ fprintf(stderr, "%s[ fatal ] %s %s\n",color_red, m, color_reset); exit(EXIT_FAILURE); diff --git a/src/lua.c b/src/lua.c index 91c667b..5c60fe8 100644 --- a/src/lua.c +++ b/src/lua.c @@ -7,6 +7,19 @@ #include "parray.h" static int ii = 0; +static int malloc_count = 0; + +void* __malloc_(size_t N){ + printf("hi"); + malloc_count++; + return (malloc)(N); +} + +void __free_(void* p){ + malloc_count--; + printf("%i\n",malloc_count); + return (free)(p); +} int writer(lua_State *L, const void* p, size_t sz, void* ud){ char o[2] = {0}; @@ -55,15 +68,7 @@ void i_dcopy(lua_State* src, lua_State* dest, void* _seen){ lua_pop(dest, 1); lua_rawgeti(dest, LUA_REGISTRYINDEX, *(int*)whar); - //lua_pushnumber(dest, 23); - /*int abb = lua_gettop(src); - l_pprint(src); - lua_settop(src, abb); - abb = lua_gettop(dest); - printf("\n**\n"); - l_pprint(dest); - lua_settop(dest, abb); - printf("used %i\n",*(int*)whar);*/ + return; } //lua_pushinteger(dest, 55); diff --git a/src/lua.h b/src/lua.h index 7145098..30eefb4 100644 --- a/src/lua.h +++ b/src/lua.h @@ -1,6 +1,10 @@ #include #include #include +#include + +void* __malloc_(size_t); +void __free_(void*); void i_dcopy(lua_State* src, lua_State* dest, void*); diff --git a/src/net.c b/src/net.c index e39685b..c3239e5 100644 --- a/src/net.c +++ b/src/net.c @@ -397,6 +397,7 @@ void* handle_client(void *_arg){ void* v = parray_find(paths, aa->c); + str_free(aa); if(v == NULL){ str* resp; http_build(&resp, 404, "Not Found","text/html", "

404

"); @@ -461,7 +462,7 @@ void* handle_client(void *_arg){ } } } - parray_lclear(owo); + parray_lclear(owo); //dont free the rest lua_pushstring(L, "client_fd"); lua_gettable(L, res_idx); @@ -471,7 +472,7 @@ void* handle_client(void *_arg){ } - for(int i = 0; i != len; i++){ + for(int i = 0; i != len * 2; i++){ str_free(table[i]); } free(table); @@ -556,6 +557,7 @@ int start_serv(lua_State* L, int port){ pthread_create(&thread_id, NULL, handle_client, (void*)args); pthread_detach(thread_id); + free(client_fd); } } diff --git a/src/parray.c b/src/parray.c index d0e38ff..77c9771 100644 --- a/src/parray.c +++ b/src/parray.c @@ -3,6 +3,7 @@ #include #include +#include "lua.h" #include "parray.h" parray_t* parray_init(){ -- cgit v1.2.3