[Dnsmasq-discuss] Memory leak + fix
Tim Wilkinson
tim.j.wilkinson at gmail.com
Thu May 29 04:56:51 UTC 2025
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);
}
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/attachments/20250528/4d319c3f/attachment.htm>
More information about the Dnsmasq-discuss
mailing list