We use dnsmasq as part of our AREDN platform (arednmesh.org 
<http://arednmesh.org/>) which is in turn based on OpenWRT (openwrt.org 
<http://openwrt.org/>). In our particular setup we watch a directory of host 
files, sometimes thousands of them, and they change frequently. With this 
configuration we’ve noticed a slow memory leak which looks to be caused by 
these frequent file changes. We fixed this with the included patch (see below). 
Please take a look. Essentially the assumption in the current code is that the 
function dyndir_addhosts is passed a malloced “path” which should not be freed 
unless it errors, but because this path is usually found in the struct dyndir 
file cache this isn’t (usually) true. And so the path leaks.

Thanks
Tim - KN6PLV

--- a/src/inotify.c
+++ b/src/inotify.c
@@ -155,6 +155,11 @@
   newah->index = daemon->host_index++;
   newah->fname = path;
 
+  if (!(newah->fname = whine_malloc(strlen(path)+1))) {
+    free(newah);
+    return NULL;
+  }
+  strcpy(newah->fname, path);
   return newah;
 }
 
@@ -239,6 +244,8 @@
                     option_read_dynfile(path, dd->flags);
 #endif            
                 }
+
+              free(path);
             }
         }
 
@@ -339,8 +346,7 @@
                      option_read_dynfile(path, AH_DHCP_OPT);
 #endif
                    
-                   if (!ah)
-                     free(path);
+                   free(path);
                  }
              }
        }

_______________________________________________
Dnsmasq-discuss mailing list
Dnsmasq-discuss@lists.thekelleys.org.uk
https://lists.thekelleys.org.uk/cgi-bin/mailman/listinfo/dnsmasq-discuss

Reply via email to