patches for a few memory leaks

From: Radu Greab <radu@dont-contact.us>
Date: Fri, 25 May 2001 06:10:03 +0300

I sent this to Duanne but I haven't got any reply yet, so I presume
that he is not available. The following patches are against
squid-2.4.STABLE1.

1. Squid leaks 72 bytes every minute because it does not free data
   allocated for comm_dns_incoming counter:

--- squid-2.4.STABLE1/src/stat.c.orig Fri Jan 12 02:51:52 2001
+++ squid-2.4.STABLE1/src/stat.c Wed May 23 22:24:19 2001
@@ -1002,6 +1002,7 @@
     statHistClean(&C->dns.svc_time);
     statHistClean(&C->cd.on_xition_count);
     statHistClean(&C->comm_icp_incoming);
+ statHistClean(&C->comm_dns_incoming);
     statHistClean(&C->comm_http_incoming);
     statHistClean(&C->select_fds_hist);
 }

2. snmpAddNode() duplicates the oid created by snmpCreateOid() and
   does not free the original. A few bytes leaked at start-up.

--- squid-2.4.STABLE1/src/snmp_core.c.orig Fri Jan 12 02:51:51 2001
+++ squid-2.4.STABLE1/src/snmp_core.c Wed May 23 22:25:03 2001
@@ -958,7 +958,7 @@
 
     va_start(args, children);
     entry = xmalloc(sizeof(mib_tree_entry));
- entry->name = snmpOidDup(name, len);
+ entry->name = name;
     entry->len = len;
     entry->parsefunction = parsefunction;
     entry->instancefunction = instancefunction;

3. If Squid is configured as a httpd accelerator, then it leaks
   Config2.Accel.prefix at every reconfigure/log rotation. I moved the
   initialization and the memory freeing code into cf_gen.c. The
   code will be put into the generated default_all() and
   free_all(). Is this the right approach?

--- squid-2.4.STABLE1/src/cache_cf.c.orig Thu Mar 1 23:49:25 2001
+++ squid-2.4.STABLE1/src/cache_cf.c Thu May 24 07:27:23 2001
@@ -259,7 +259,6 @@
 configDoConfigure(void)
 {
     LOCAL_ARRAY(char, buf, BUFSIZ);
- memset(&Config2, '\0', sizeof(SquidConfig2));
     /* init memory as early as possible */
     memConfigure();
     /* Sanity checks */
--- squid-2.4.STABLE1/src/cf_gen.c.orig Fri Jan 12 02:51:45 2001
+++ squid-2.4.STABLE1/src/cf_gen.c Thu May 24 07:26:27 2001
@@ -383,6 +383,8 @@
         "{\n"
         "\tcfg_filename = \"Default Configuration\";\n"
         "\tconfig_lineno = 0;\n"
+ "\n"
+ "\tmemset(&Config2, '\\0', sizeof(SquidConfig2));\n"
         );
     for (entry = head; entry != NULL; entry = entry->next) {
         assert(entry->name);
@@ -549,6 +551,7 @@
         if (entry->ifdef)
             fprintf(fp, "#endif\n");
     }
+ fprintf(fp, "\tfree_string(&Config2.Accel.prefix);\n");
     fprintf(fp, "}\n\n");
 }

4. If squid is compiled with support for delay pools but no pools are
   configured, then squid will leak a few bytes at every
   reconfigure/log rotation.

--- squid-2.4.STABLE1/src/cache_cf.c.orig Thu Mar 1 23:49:25 2001
+++ squid-2.4.STABLE1/src/cache_cf.c Thu May 24 02:40:42 2001
@@ -682,10 +682,12 @@
         free_delay_pool_count(cfg);
     }
     parse_ushort(&cfg->pools);
- delayInitDelayData(cfg->pools);
- cfg->class = xcalloc(cfg->pools, sizeof(u_char));
- cfg->rates = xcalloc(cfg->pools, sizeof(delaySpecSet *));
- cfg->access = xcalloc(cfg->pools, sizeof(acl_access *));
+ if (cfg->pools) {
+ delayInitDelayData(cfg->pools);
+ cfg->class = xcalloc(cfg->pools, sizeof(u_char));
+ cfg->rates = xcalloc(cfg->pools, sizeof(delaySpecSet *));
+ cfg->access = xcalloc(cfg->pools, sizeof(acl_access *));
+ }
 }
 
 static void

I'll appreciate your replies to be cc-ed to me as I'm not subscribed
to the list.

Thank you,
Radu Greab
Received on Sat May 26 2001 - 14:10:32 MDT

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:14:02 MST