From 5acd7854cc54ae583e48de029d5e20dc4ab3154b Mon Sep 17 00:00:00 2001 From: Augustin Fabre Date: Tue, 31 Mar 2020 22:50:53 +0200 Subject: [PATCH 1/2] Fix memory leak in gophermap parsing FILE pointer `fp' was not closed when the gophermap parsing returned early. --- Makefile | 2 +- src/menu.c | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index de0c60a..8545416 100644 --- a/Makefile +++ b/Makefile @@ -72,7 +72,7 @@ src/functions.h: grep -h "^[a-z]" $(SOURCES) | \ grep -v "int main" | \ grep -v "strlc" | \ - grep -v "[a-z]:" | \ + grep -vi "[a-z]:" | \ sed -e "s/ =.*$$//" -e "s/ *$$/;/" >> $@ @echo diff --git a/src/menu.c b/src/menu.c index 9e25716..083d352 100644 --- a/src/menu.c +++ b/src/menu.c @@ -283,6 +283,7 @@ int gophermap(state *st, char *mapfile, int depth) char type; int port; int exe; + int return_val = QUIT; /* Prevent include loops */ if (depth > 4) return OK; @@ -343,8 +344,13 @@ int gophermap(state *st, char *mapfile, int depth) if (type == '#') continue; /* Stop handling gophermap? */ - if (type == '*') return OK; - if (type == '.') return QUIT; + if (type == '*') { + return_val = OK; + goto CLOSE_FP; + } + if (type == '.') + goto CLOSE_FP; + /* Print a list of users with public_gopher */ if (type == '~' && st->opt_personal_spaces) { @@ -435,14 +441,14 @@ int gophermap(state *st, char *mapfile, int depth) } } - /* Clean up & return */ +CLOSE_FP: #ifdef HAVE_POPEN if (exe & st->opt_exec) pclose(fp); else #endif fclose(fp); - return QUIT; + return return_val; } From 53ccff987bc7ef4c76c4fb7316b44497007e3b25 Mon Sep 17 00:00:00 2001 From: Augustin Fabre Date: Thu, 2 Apr 2020 09:35:12 +0200 Subject: [PATCH 2/2] Propagate FLAGS value to recursive MAKE calls --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 8545416..fa9b57e 100644 --- a/Makefile +++ b/Makefile @@ -46,12 +46,12 @@ IPCRM = /usr/bin/ipcrm all: @case $$(uname) in \ Darwin) $(MAKE) ROOT="$(OSXROOT)" DESTDIR="$(OSXDIr)" src/$(BINARY); ;; \ - Haiku) $(MAKE) LDFLAGS="-lnetwork" src/$(BINARY); ;; \ + Haiku) $(MAKE) LDFLAGS="$(LDFLAGS) -lnetwork" src/$(BINARY); ;; \ *) if [ -f "/usr/include/tcpd.h" ]; then $(MAKE) withwrap; else $(MAKE) src/$(BINARY); fi; ;; \ esac withwrap: - $(MAKE) CFLAGS="-DHAVE_LIBWRAP" LDFLAGS="-lwrap" src/$(BINARY) + $(MAKE) CFLAGS="$(CFLAGS) -DHAVE_LIBWRAP" LDFLAGS="$(LDFLAGS) -lwrap" src/$(BINARY) deb: dpkg-buildpackage -rfakeroot -uc -us