From 8bdc1c7631969c322bf0187ce94dbd1a2d8a2a9f Mon Sep 17 00:00:00 2001 From: Emil Renner Berthing Date: Fri, 24 May 2013 17:42:23 +0200 Subject: io: fix memory leak on error in io.popen() --- lem/io/core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lem/io/core.c b/lem/io/core.c index d41c3d0..27ece00 100644 --- a/lem/io/core.c +++ b/lem/io/core.c @@ -269,11 +269,11 @@ io_popen(lua_State *T) int fd[2]; int err; - posix_spawn_file_actions_init(&fa); switch (mode) { case 0: /* "r" */ if (pipe(fd)) return io_strerror(T, errno); + posix_spawn_file_actions_init(&fa); posix_spawn_file_actions_adddup2(&fa, fd[1], 1); posix_spawn_file_actions_addclose(&fa, fd[1]); break; @@ -283,12 +283,14 @@ io_popen(lua_State *T) err = fd[0]; fd[0] = fd[1]; fd[1] = err; + posix_spawn_file_actions_init(&fa); posix_spawn_file_actions_adddup2(&fa, fd[1], 0); posix_spawn_file_actions_addclose(&fa, fd[1]); break; case 2: /* "rw" */ if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) return io_strerror(T, errno); + posix_spawn_file_actions_init(&fa); posix_spawn_file_actions_adddup2(&fa, fd[1], 0); posix_spawn_file_actions_adddup2(&fa, fd[1], 1); posix_spawn_file_actions_addclose(&fa, fd[1]); -- cgit v1.2.1