Linux NFS development
 help / color / mirror / Atom feed
* [PATCH] statd: fix memory leak in sm_mon_1_svc() when existing host re-monitors
@ 2026-07-28  8:33 xuchenchen
  2026-08-15 20:46 ` Steve Dickson
  0 siblings, 1 reply; 2+ messages in thread
From: xuchenchen @ 2026-07-28  8:33 UTC (permalink / raw)
  To: linux-nfs; +Cc: steved, xuchenchen

From: xuchenchen <xuchenchen@kylinos.cn>

When an already-monitored host sends a new SM_MON request with a
different priv cookie, the code sets existing=1 and reuses the
existing notify_list entry. However, clnt->dns_name is overwritten
with the newly allocated dnsname without freeing the old value,
causing a memory leak.

Since statd is a long-running daemon, repeated SM_MON requests with
changing cookies will accumulate leaked strings.

Fix by freeing the old dns_name before overwriting it.

Signed-off-by: xuchenchen <xuchenchen@kylinos.cn>
---
 utils/statd/monitor.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/utils/statd/monitor.c b/utils/statd/monitor.c
index c76589ca..76ef16f1 100644
--- a/utils/statd/monitor.c
+++ b/utils/statd/monitor.c
@@ -187,6 +187,8 @@ sm_mon_1_svc(struct mon *argp, struct svc_req *rqstp)
 	NL_MY_VERS(clnt) = id->my_vers;
 	NL_MY_PROC(clnt) = id->my_proc;
 	memcpy(NL_PRIV(clnt), argp->priv, SM_PRIV_SIZE);
+	if (existing)
+		free(clnt->dns_name);
 	clnt->dns_name = dnsname;
 
 	/*
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] statd: fix memory leak in sm_mon_1_svc() when existing host re-monitors
  2026-07-28  8:33 [PATCH] statd: fix memory leak in sm_mon_1_svc() when existing host re-monitors xuchenchen
@ 2026-08-15 20:46 ` Steve Dickson
  0 siblings, 0 replies; 2+ messages in thread
From: Steve Dickson @ 2026-08-15 20:46 UTC (permalink / raw)
  To: xuchenchen, linux-nfs; +Cc: xuchenchen



On 7/28/26 4:33 AM, xuchenchen wrote:
> From: xuchenchen <xuchenchen@kylinos.cn>
> 
> When an already-monitored host sends a new SM_MON request with a
> different priv cookie, the code sets existing=1 and reuses the
> existing notify_list entry. However, clnt->dns_name is overwritten
> with the newly allocated dnsname without freeing the old value,
> causing a memory leak.
> 
> Since statd is a long-running daemon, repeated SM_MON requests with
> changing cookies will accumulate leaked strings.
> 
> Fix by freeing the old dns_name before overwriting it.
> 
> Signed-off-by: xuchenchen <xuchenchen@kylinos.cn>
Committed... (tag: nfs-utils-2-9-3-rc1)

steved.> ---
>   utils/statd/monitor.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/utils/statd/monitor.c b/utils/statd/monitor.c
> index c76589ca..76ef16f1 100644
> --- a/utils/statd/monitor.c
> +++ b/utils/statd/monitor.c
> @@ -187,6 +187,8 @@ sm_mon_1_svc(struct mon *argp, struct svc_req *rqstp)
>   	NL_MY_VERS(clnt) = id->my_vers;
>   	NL_MY_PROC(clnt) = id->my_proc;
>   	memcpy(NL_PRIV(clnt), argp->priv, SM_PRIV_SIZE);
> +	if (existing)
> +		free(clnt->dns_name);
>   	clnt->dns_name = dnsname;
>   
>   	/*


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-08-15 20:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-28  8:33 [PATCH] statd: fix memory leak in sm_mon_1_svc() when existing host re-monitors xuchenchen
2026-08-15 20:46 ` Steve Dickson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox