From b70b777f37b85a6d4ef72b8e08f2469b4777266d Mon Sep 17 00:00:00 2001 From: greg-a Date: Thu, 28 Nov 2013 21:42:08 +0100 Subject: fix error and mem leak found by cppcheck --- 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 4c8186d..b3f537b 100644 --- a/src/loadlib_rel.c +++ b/src/loadlib_rel.c @@ -141,7 +141,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); @@ -186,6 +186,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