aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/i_str.c1
-rw-r--r--src/i_util.c1
-rw-r--r--src/lua.c23
-rw-r--r--src/lua.h4
-rw-r--r--src/net.c6
-rw-r--r--src/parray.c1
-rw-r--r--tests/net.lua8
7 files changed, 30 insertions, 14 deletions
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 <stdio.h>
#include <stdlib.h>
#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 <lua.h>
#include <lualib.h>
#include <lauxlib.h>
+#include <stdlib.h>
+
+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", "<h1>404</h1>");
@@ -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 <stdlib.h>
#include <string.h>
+#include "lua.h"
#include "parray.h"
parray_t* parray_init(){
diff --git a/tests/net.lua b/tests/net.lua
index 3320355..f521bc7 100644
--- a/tests/net.lua
+++ b/tests/net.lua
@@ -34,18 +34,20 @@ llib.net.listen(
--print("hi from first")
--llib.io.pprint(llib.crypto.md5("hewwo"))
--_G.sleep(1)
- _G.llib.io.pprint(_G._G._G._llib.crypto.md5("hi"))
+ --_G.llib.io.pprint(_G._G._G._llib.crypto.md5("hi"))
--_G.llib.io.pprint(_G._Go)
--_G.llib.io.pprint(_G.wo.crypto.md5("55"))
end)
server:GET("/aa", function(res, req)
- res.header["Content-Type"] = "text/plain"
+ --[[res.header["Content-Type"] = "text/plain"
_G.server:lock()
res:write("hi\n")
res:write("next")
_G.server:unlock()
- res:close()
+ res:close()]]
+ res.header["Content-Type"] = "text/plain"
+ res:send(_G.llib.io.readfile("tests/net.lua"))
end)
server:GET("/test", function(res, req)