All of lore.kernel.org
 help / color / mirror / Atom feed
From: "J. Bruce Fields" <bfields@fieldses.org>
To: Kinglong Mee <kinglongmee@gmail.com>
Cc: Trond Myklebust <trond.myklebust@primarydata.com>,
	Linux NFS Mailing List <linux-nfs@vger.kernel.org>
Subject: Re: [PATCH] SUNRPC: fix memory leak of peer addresses in XPRT
Date: Mon, 6 Jan 2014 15:20:24 -0500	[thread overview]
Message-ID: <20140106202024.GD31764@fieldses.org> (raw)
In-Reply-To: <52CA8460.6030206@gmail.com>

On Mon, Jan 06, 2014 at 06:24:32PM +0800, Kinglong Mee wrote:
> If creating xprt failed after xs_format_peer_addresses,
> sunrpc must free those memory of peer addresses in xprt.
> 
> Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
> ---
>  net/sunrpc/xprtsock.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
> index 25dbfa9..11ceba3 100644
> --- a/net/sunrpc/xprtsock.c
> +++ b/net/sunrpc/xprtsock.c
> @@ -2725,8 +2725,10 @@ static struct rpc_xprt *xs_setup_local(struct xprt_create *args)
>  		xprt_set_bound(xprt);
>  		xs_format_peer_addresses(xprt, "local", RPCBIND_NETID_LOCAL);
>  		ret = ERR_PTR(xs_local_setup_socket(transport));
> -		if (ret)
> +		if (ret) {
> +			xs_free_peer_addresses(xprt);
>  			goto out_err;
> +		}
>  		break;
>  	default:
>  		ret = ERR_PTR(-EAFNOSUPPORT);
> @@ -2738,6 +2740,8 @@ static struct rpc_xprt *xs_setup_local(struct xprt_create *args)
>  
>  	if (try_module_get(THIS_MODULE))
>  		return xprt;
> +
> +	xs_free_peer_addresses(xprt);
>  	ret = ERR_PTR(-EINVAL);
>  out_err:
>  	xprt_free(xprt);

This is getting a little hairy.... Looks like xprts are alloc'd with
kzalloc() and xs_free_peer_addresses is a no-op if
xprt->address_strings[i] is NULL, so it looks safe to call
unconditionally after out_err?

> @@ -2816,6 +2820,8 @@ static struct rpc_xprt *xs_setup_udp(struct xprt_create *args)
>  
>  	if (try_module_get(THIS_MODULE))
>  		return xprt;
> +
> +	xs_free_peer_addresses(xprt);
>  	ret = ERR_PTR(-EINVAL);
>  out_err:
>  	xprt_free(xprt);
> @@ -2893,9 +2899,10 @@ static struct rpc_xprt *xs_setup_tcp(struct xprt_create *args)
>  				xprt->address_strings[RPC_DISPLAY_ADDR],
>  				xprt->address_strings[RPC_DISPLAY_PROTO]);
>  
> -
>  	if (try_module_get(THIS_MODULE))
>  		return xprt;
> +
> +	xs_free_peer_addresses(xprt);
>  	ret = ERR_PTR(-EINVAL);
>  out_err:
>  	xprt_free(xprt);
> -- 
> 1.8.4.2

And after this we'll end up with

	xs_free_peer_addresses(xprt);
	xprt_free(xprt);

in 4 different places (the above plus xs_destroy), so I might define an
xs_xprt_free() to do that.

--b.

  reply	other threads:[~2014-01-06 20:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-06 10:24 [PATCH] SUNRPC: fix memory leak of peer addresses in XPRT Kinglong Mee
2014-01-06 20:20 ` J. Bruce Fields [this message]
2014-01-07  3:49   ` Kinglong Mee
2014-03-23 13:24     ` Kinglong Mee
2014-03-24  3:07       ` [PATCH][RESEND] " Kinglong Mee
2014-03-29  0:55         ` J. Bruce Fields
2014-03-25  0:05       ` [PATCH] " J. Bruce Fields

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140106202024.GD31764@fieldses.org \
    --to=bfields@fieldses.org \
    --cc=kinglongmee@gmail.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=trond.myklebust@primarydata.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.