From a77a47e2f059c0285bbc339fa080ee1c1b144710 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Draho=C5=A1?= Date: Sun, 8 Dec 2013 14:51:09 +0100 Subject: Memory leak fix --- src/loadlib_rel.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/loadlib_rel.c b/src/loadlib_rel.c index ea9f044..0556ba9 100644 --- a/src/loadlib_rel.c +++ b/src/loadlib_rel.c @@ -75,7 +75,7 @@ static void setprogdir(lua_State *L) { char progdir[_PATH_MAX + 1]; char *lb; int nsize = sizeof(progdir)/sizeof(char); - int n; + int n = 0; #if defined(__CYGWIN__) char win_buff[_PATH_MAX + 1]; GetModuleFileNameA(NULL, win_buff, nsize); @@ -120,6 +120,7 @@ static void setprogdir(lua_State *L) { sprintf(cmd, "lsof -p %d | awk '{if ($5==\"REG\") { print $9 ; exit}}' 2> /dev/null", pid); fd = popen(cmd, "r"); n = fread(progdir, 1, nsize, fd); + pclose(fd); // remove newline if (n > 1) progdir[--n] = '\0'; -- cgit v1.2.1