handlegph: fix memory leak if writing a line failed - geomyidae - A small C-based gopherd.
git clone git://bitreich.org/geomyidae/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/geomyidae/
Log
Files
Refs
Tags
README
LICENSE
---
commit 997f994cfd4318cdd6b9d40f5864b37002976cac
parent 70d5d67d68410c852d9663a6e4935e508897ffdf
Author: Hiltjo Posthuma 
Date:   Wed,  8 Mar 2023 20:56:42 +0100

handlegph: fix memory leak if writing a line failed

Signed-off-by: Christoph Lohmann <20h@r-36.net>

Diffstat:
  M handlr.c                            |       7 ++++---

1 file changed, 4 insertions(+), 3 deletions(-)
---
diff --git a/handlr.c b/handlr.c
@@ -108,13 +108,14 @@ handlegph(int sock, char *file, char *port, char *base, char *args,
 
         act = scanfile(file);
         if (act != NULL) {
-                for (i = 0; i < act->num && ret >= 0; i++) {
+                for (i = 0; i < act->num && ret >= 0; i++)
                         ret = printelem(sock, act->n[i], file, base, ohost, port);
+                dprintf(sock, ".\r\n");
+
+                for (i = 0; i < act->num; i++) {
                         freeelem(act->n[i]);
                         act->n[i] = NULL;
                 }
-                dprintf(sock, ".\r\n");
-
                 freeindex(act);
         }
 }