From 59f6cd5453212f2401a9e6327350cc3ca4cd74f8 Mon Sep 17 00:00:00 2001 From: Hleran Date: Sat, 18 Jul 2015 23:28:12 +0300 Subject: [PATCH] lua_plugin: rpc uwsgi_malloc and missing free I noticed that all cool kids are using uwsgi_malloc instead of malloc; Also I noticed, that I forgot to free memory last time (while playing on high level languages) --- plugins/lua/lua_plugin.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/plugins/lua/lua_plugin.c b/plugins/lua/lua_plugin.c index 12839d80..58aeafce 100644 --- a/plugins/lua/lua_plugin.c +++ b/plugins/lua/lua_plugin.c @@ -93,8 +93,8 @@ static int uwsgi_api_rpc(lua_State *L) { if (argc > 0) { uint8_t i; - argv = (char **) malloc(sizeof(char **)*argc); - argvs = (uint16_t *) malloc(sizeof(uint16_t *)*argc); + argv = (char **) uwsgi_malloc(sizeof(char **)*argc); + argvs = (uint16_t *) uwsgi_malloc(sizeof(uint16_t *)*argc); for(i = 0; i < argc; i++) { argv[i] = (char *) lua_tolstring(L, i + 3, (size_t *) &argvs[i]); @@ -110,6 +110,13 @@ static int uwsgi_api_rpc(lua_State *L) { lua_pushlstring(L, str, len); } + if (argc > 0) { + free(argv); + free(argvs); + } + + free(str); + return 1; }