From 1f019ceea1ed39286e6bccfb3ff936c22fe0f7c0 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 21 Jun 2016 17:19:10 +0200 Subject: Fix various memory management issues Consistently handle allocation failures. Some functions are changed to return bool or int instead of void to allow returning an error. Also fix a buffer size miscalculation in lua/uloop and use _exit() instead of exit() on errors after forking. Signed-off-by: Matthias Schiffer --- lua/uloop.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lua') diff --git a/lua/uloop.c b/lua/uloop.c index 782b5a5..c5dd12f 100644 --- a/lua/uloop.c +++ b/lua/uloop.c @@ -325,9 +325,12 @@ static int ul_process(lua_State *L) int argn = lua_objlen(L, -3); int envn = lua_objlen(L, -2); char** argp = malloc(sizeof(char*) * (argn + 2)); - char** envp = malloc(sizeof(char*) * envn + 1); + char** envp = malloc(sizeof(char*) * (envn + 1)); int i = 1; + if (!argp || !envp) + _exit(-1); + argp[0] = (char*) lua_tostring(L, -4); for (i = 1; i <= argn; i++) { lua_rawgeti(L, -3, i); @@ -344,7 +347,7 @@ static int ul_process(lua_State *L) envp[i - 1] = NULL; execve(*argp, argp, envp); - exit(-1); + _exit(-1); } lua_getglobal(L, "__uloop_cb"); -- cgit v1.2.3