about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorThomas E. Dickey <dickey@invisible-island.net>2018-03-29 00:38:59 +0000
committerThomas E. Dickey <dickey@invisible-island.net>2018-03-29 00:38:59 +0000
commitac9f8d52a8715476153ade910dd81436bfdea2a7 (patch)
treef3ad7d4cdd50c3d4b5f8caf57438279c53756dc9
parentd59cf1e795c0628c2f8b4dce3052627ecdad20a8 (diff)
downloadlynx-snapshots-ac9f8d52a8715476153ade910dd81436bfdea2a7.tar.gz
snapshot of project "lynx", label v2-8-9dev_17d
-rw-r--r--CHANGES3
-rw-r--r--WWW/Library/Implementation/HTTCP.c34
-rw-r--r--WWW/Library/Implementation/HTTCP.h13
-rw-r--r--src/LYHash.c39
-rw-r--r--src/LYMain.c5
-rw-r--r--src/LYUtils.c8
6 files changed, 69 insertions, 33 deletions
diff --git a/CHANGES b/CHANGES
index c4fb2bc1..698e903c 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,9 +1,10 @@
--- $LynxId: CHANGES,v 1.968 2018/03/28 20:09:55 tom Exp $
+-- $LynxId: CHANGES,v 1.969 2018/03/28 22:33:40 tom Exp $
 ===============================================================================
 Changes since Lynx 2.8 release
 ===============================================================================
 
 2018-03-28 (2.8.9dev.18)
+* fix a few more memory leaks -TD
 * put Lynx.leaks file in home directory like Lynx.trace (report by GV) -TD
 * fix a memory leak in HTFTP.c -GV
 * modify HTDoConnect(), adding a check for keyboard interrupt with 'z' in the
diff --git a/WWW/Library/Implementation/HTTCP.c b/WWW/Library/Implementation/HTTCP.c
index aad7e59c..ebcfcaef 100644
--- a/WWW/Library/Implementation/HTTCP.c
+++ b/WWW/Library/Implementation/HTTCP.c
@@ -1,5 +1,5 @@
 /*
- * $LynxId: HTTCP.c,v 1.141 2018/03/28 00:44:27 tom Exp $
+ * $LynxId: HTTCP.c,v 1.143 2018/03/28 22:29:45 tom Exp $
  *
  *			Generic Communication Code		HTTCP.c
  *			==========================
@@ -32,6 +32,9 @@
 #ifdef NSL_FORK
 #include <signal.h>
 #include <www_wait.h>
+#define FREE_NSL_FORK(p) FREE(p)
+#else
+#define FREE_NSL_FORK(p)	/* nothing */
 #endif /* NSL_FORK */
 
 #ifdef HAVE_RESOLV_H
@@ -1115,7 +1118,7 @@ static void really_gethostbyname(const char *host,
  *	HT_ERROR		Resolver error, reason not known
  *	HT_INTERNAL		Internal error
  */
-LYNX_HOSTENT *LYGetHostByName(char *host)
+static LYNX_HOSTENT *LYGetHostByName(char *host)
 {
     static const char *this_func = "LYGetHostByName";
 
@@ -1259,6 +1262,15 @@ LYNX_HOSTENT *LYGetHostByName(char *host)
     return NULL;
 }
 
+BOOLEAN LYCheckHostByName(char *host)
+{
+    LYNX_HOSTENT *data = LYGetHostByName(host);
+    BOOLEAN result = (data != NULL);
+
+    FREE_NSL_FORK(data);
+    return result;
+}
+
 /*	Parse a network node address and port
  *	-------------------------------------
  *
@@ -1393,6 +1405,7 @@ static int HTParseInet(SockA * soc_in, const char *str)
 		HTAlwaysAlert(host, gettext("Address length looks invalid"));
 	    }
 	    MemCpy((void *) &soc_in->sin_addr, phost->h_addr_list[0], phost->h_length);
+	    FREE_NSL_FORK(phost);
 	}
 #endif /* _WINDOWS_NSL */
 
@@ -1593,8 +1606,8 @@ static void really_getaddrinfo(const char *host,
 }
 #endif /* NSL_FORK */
 
-LYNX_ADDRINFO *HTGetAddrInfo(const char *str,
-			     const int defport)
+static LYNX_ADDRINFO *HTGetAddrInfo(const char *str,
+				    const int defport)
 {
 #ifdef NSL_FORK
     /* for transfer of result between from child to parent: */
@@ -1654,6 +1667,15 @@ LYNX_ADDRINFO *HTGetAddrInfo(const char *str,
 #endif
     return res;
 }
+
+BOOLEAN HTCheckAddrInfo(const char *str, const int defport)
+{
+    LYNX_ADDRINFO *data = HTGetAddrInfo(str, defport);
+    BOOLEAN result = (data != 0);
+
+    FREE_NSL_FORK(data);
+    return result;
+}
 #endif /* INET6 */
 
 #ifdef LY_FIND_LEAKS
@@ -2181,7 +2203,9 @@ int HTDoConnect(const char *url,
 
 #ifdef INET6
     FREE(line);
-#ifndef NSL_FORK
+#ifdef NSL_FORK
+    FREE_NSL_FORK(res0);
+#else
     if (res0)
 	freeaddrinfo(res0);
 #endif
diff --git a/WWW/Library/Implementation/HTTCP.h b/WWW/Library/Implementation/HTTCP.h
index a1e83782..878053ce 100644
--- a/WWW/Library/Implementation/HTTCP.h
+++ b/WWW/Library/Implementation/HTTCP.h
@@ -1,5 +1,5 @@
 /*
- * $LynxId: HTTCP.h,v 1.24 2014/12/03 00:27:57 tom Exp $
+ * $LynxId: HTTCP.h,v 1.25 2018/03/28 21:14:18 tom Exp $
  *
  *                               /Net/dxcern/userd/timbl/hypertext/WWW/Library/src/HTTCP.html
  *                             GENERIC TCP/IP COMMUNICATION
@@ -88,17 +88,10 @@ extern "C" {
  */
     extern int lynx_nsl_status;
 
-#ifndef LYNX_HOSTENT
-#define LYNX_HOSTENT void
-#endif
-
-    extern LYNX_HOSTENT *LYGetHostByName(char *host);
+    extern BOOLEAN LYCheckHostByName(char *host);
 
 #ifdef INET6
-#ifndef LYNX_ADDRINFO
-#define LYNX_ADDRINFO void
-#endif
-    extern LYNX_ADDRINFO *HTGetAddrInfo(const char *str, const int defport);
+    extern BOOLEAN HTCheckAddrInfo(const char *str, const int defport);
 #endif
 
 /*      Get Name of This Machine
diff --git a/src/LYHash.c b/src/LYHash.c
index 3aa8e2fe..f419c7ea 100644
--- a/src/LYHash.c
+++ b/src/LYHash.c
@@ -1,5 +1,5 @@
 /*
- * $LynxId: LYHash.c,v 1.38 2018/03/10 01:50:19 tom Exp $
+ * $LynxId: LYHash.c,v 1.39 2018/03/29 00:38:59 tom Exp $
  *
  * A hash table for the (fake) CSS support in Lynx-rp
  * (c) 1996 Rob Partington
@@ -10,9 +10,12 @@
 #include <LYUtils.h>
 #include <LYLeaks.h>
 #include <LYStrings.h>
+#include <LYGlobalDefs.h>
 
 #ifdef USE_COLOR_STYLE
 
+#undef HASH_TYPE
+
 #define HASH_SIZE CSHASHSIZE
 #define HASH_TYPE     int
 #define HASH_OF(h, v) ((HASH_TYPE)((h) * 3 + UCH(v)) % HASH_SIZE)
@@ -79,20 +82,34 @@ static HASH_TYPE cs_hash(const char *string)
 
 int color_style_1(const char *string)
 {
-    get_buffer(strlen(string));
-    strcpy(buffer, string);
-    LYLowerCase(buffer);
-    return cs_hash(buffer);
+    int hash;
+
+    if (dump_output_immediately) {
+	hash = 0;
+    } else {
+	get_buffer(strlen(string));
+	strcpy(buffer, string);
+	LYLowerCase(buffer);
+	hash = cs_hash(buffer);
+    }
+    return hash;
 }
 
 int color_style_3(const char *p, const char *q, const char *r)
 {
-    get_buffer(strlen(p) + strlen(q) + strlen(r));
-    strcpy(buffer, p);
-    strcat(buffer, q);
-    strcat(buffer, r);
-    LYLowerCase(buffer);
-    return cs_hash(buffer);
+    int hash;
+
+    if (dump_output_immediately) {
+	hash = 0;
+    } else {
+	get_buffer(strlen(p) + strlen(q) + strlen(r));
+	strcpy(buffer, p);
+	strcat(buffer, q);
+	strcat(buffer, r);
+	LYLowerCase(buffer);
+	hash = cs_hash(buffer);
+    }
+    return hash;
 }
 
 void report_hashStyles(void)
diff --git a/src/LYMain.c b/src/LYMain.c
index bccb6e47..054db9e1 100644
--- a/src/LYMain.c
+++ b/src/LYMain.c
@@ -1,5 +1,5 @@
 /*
- * $LynxId: LYMain.c,v 1.277 2018/03/28 20:07:59 tom Exp $
+ * $LynxId: LYMain.c,v 1.278 2018/03/28 21:41:50 tom Exp $
  */
 #include <HTUtils.h>
 #include <HTTP.h>
@@ -1043,7 +1043,6 @@ int main(int argc,
 #endif
 
 #ifdef LY_FIND_LEAKS
-    LYAddPathToHome(LYLeaksPath, (size_t) LY_MAXPATH, LEAKAGE_SINK);
     /*
      * Register the final function to be executed when being exited.  Will
      * display memory leaks if the -find-leaks option is used.  This should
@@ -1055,6 +1054,8 @@ int main(int argc,
      * Register the function which will free our allocated globals.
      */
     atexit(free_lynx_globals);
+
+    LYAddPathToHome(LYLeaksPath, (size_t) LY_MAXPATH, LEAKAGE_SINK);
 #endif /* LY_FIND_LEAKS */
 
 #ifdef    NOT_ASCII
diff --git a/src/LYUtils.c b/src/LYUtils.c
index 6b493afc..d123e916 100644
--- a/src/LYUtils.c
+++ b/src/LYUtils.c
@@ -1,5 +1,5 @@
 /*
- * $LynxId: LYUtils.c,v 1.290 2018/03/27 23:07:44 tom Exp $
+ * $LynxId: LYUtils.c,v 1.291 2018/03/28 21:14:39 tom Exp $
  */
 #include <HTUtils.h>
 #include <HTTCP.h>
@@ -4230,9 +4230,9 @@ static BOOLEAN LYExpandHostForURL(char **AllocatedString,
 	fprintf(stdout, "%s '%s'%s\r\n", WWW_FIND_MESSAGE, host, FIRST_SEGMENT);
     }
 #ifdef INET6
-    if (HTGetAddrInfo(host, 80) != NULL)
+    if (HTCheckAddrInfo(host, 80))
 #else
-    if (LYGetHostByName(host) != NULL)
+    if (LYCheckHostByName(host))
 #endif /* INET6 */
     {
 	/*
@@ -4334,7 +4334,7 @@ static BOOLEAN LYExpandHostForURL(char **AllocatedString,
 	    } else if (Startup && !dump_output_immediately) {
 		fprintf(stdout, "%s '%s'%s\n", WWW_FIND_MESSAGE, host, GUESSING_SEGMENT);
 	    }
-	    GotHost = (BOOL) (LYGetHostByName(host) != NULL);
+	    GotHost = LYCheckHostByName(host);
 	    if (HostColon != NULL) {
 		*HostColon = ':';
 	    }