[Dnsmasq-discuss] [PATCH] Fix DHCPv6 options memory leaks
Geert Stappers
stappers at stappers.nl
Sun Oct 1 17:55:14 UTC 2023
On Thu, Sep 28, 2023 at 08:28:35AM +0000, renmingshuai via Dnsmasq-discuss wrote:
> When I repeatedly reloaded the dnsmasq process, I found a memory
> leak. To reproduce the problem, perform the following steps:
>
> (1) Run dnsmasq as follows:
> # dnsmasq --no-hosts --no-resolv --dhcp-optsfile=/tmp/opts --dhcp-range=set:subnetUUID,2003:0:0:1499::,static,64,2h
> # cat /tmp/opts
> tag:subnetUUID,option6:domain-search,openstacklocal
> tag:subnetUUID,option6:dns-server,[2003:0:0:1499::2],[2003:0:0:1499::3]
>
> (2) Send SIGHUP to dnsmasq repeatedly
> # cat send.sh
> #!/bin/bash
> while true
> do
> kill -HUP `pidof dnsmasq`
> sleep
sleep: missing operand
> done
> # sh send.sh
>
> After a period of time, the vmRss value of the dnsmasq process keeps increasing.
>
> # date
> Fri Sep 29 12:43:27 AM CST 2023
> [root at localhost home]# ps -aux|grep dnsmasq
> dnsmasq 3322571 0.0 0.0 9044 2456 ? S 00:43 0:00 dnsmasq --no-hosts --no-resolv --dhcp-optsfile=/tmp/opts --dhcp-range=set:subnetUUID,2003:0:0:1499::,static,64,infinite
> # date
> Fri Sep 29 01:09:28 AM CST 2023
> # ps -aux|grep dnsmasq
> dnsmasq 3322571 0.1 0.0 9772 3280 ? S 00:43 0:02 dnsmasq --no-hosts --no-resolv --dhcp-optsfile=/tmp/opts --dhcp-range=set:subnetUUID,2003:0:0:1499::,static,64,infinite
>
> When we configure DHCPv6 option information by using -dhcp-optsfile,
> dnsmasq process allocates memory to store those information. However,
> when dnsmasq receives SIGHUP and reread the -dhcp-optsfile, it does
> not release the memory that store DHCPv6 options information as it
> does for DHCPv4 options.
>
> The following patch could fix this problem.
> ---
> src/option.c | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/src/option.c b/src/option.c
> index 8322725..1cf2796 100644
> --- a/src/option.c
> +++ b/src/option.c
> @@ -5734,11 +5734,11 @@ static void clear_dynamic_conf(void)
> }
> }
> -static void clear_dynamic_opt(void)
> +static void clear_dhcp_opt(struct dhcp_opt **dhcp_opts)
> {
> struct dhcp_opt *opts, *cp, **up;
> - for (up = &daemon->dhcp_opts, opts = daemon->dhcp_opts; opts; opts = cp)
> + for (up = dhcp_opts, opts = *dhcp_opts; opts; opts = cp)
> {
> cp = opts->next;
>
> @@ -5752,6 +5752,14 @@ static void clear_dynamic_opt(void)
> }
> }
> +static void clear_dynamic_opt(void)
> +{
> + clear_dhcp_opt(&daemon->dhcp_opts);
> +#ifdef HAVE_DHCP6
> + clear_dhcp_opt(&daemon->dhcp_opts6);
> +#endif
> +}
> +
> void reread_dhcp(void)
> {
> struct hostsfile *hf;
> --
> 2.33.0
That looks good to me. However:
|$ git am
|Applying: Fix DHCPv6 options memory leaks
|error: corrupt patch at line 11
|Patch failed at 0001 Fix DHCPv6 options memory leaks
|hint: Use 'git am --show-current-patch=diff' to see the failed patch
|When you have resolved this problem, run "git am --continue".
|If you prefer to skip this patch, run "git am --skip" instead.
|To restore the original branch and stop patching, run "git am --abort".
|$
See https://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/2023q3/017238.html
and make another attempt.
Groeten
Geert Stappers
--
Silence is hard to parse
More information about the Dnsmasq-discuss
mailing list