diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2016-06-21 18:19:10 +0300 |
---|---|---|
committer | Felix Fietkau <nbd@nbd.name> | 2016-06-26 13:53:51 +0300 |
commit | 1f019ceea1ed39286e6bccfb3ff936c22fe0f7c0 (patch) | |
tree | 92ec3e71ca90b1bb12ff930ac1b7abfa8c1d0e07 /lua | |
parent | c2f2c47f3e9a2d709ec82a79f6fadd3124c18781 (diff) |
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 <mschiffer@universe-factory.net>
Diffstat (limited to 'lua')
-rw-r--r-- | lua/uloop.c | 7 |
1 files changed, 5 insertions, 2 deletions
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"); |