DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] vhost: clean up per-socket mutex
@ 2017-06-12 21:29 Daniel Verkamp
  2017-06-14  8:19 ` Jens Freimann
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Verkamp @ 2017-06-12 21:29 UTC (permalink / raw)
  To: dev; +Cc: Daniel Verkamp

vsocket->conn_mutex was allocated with pthread_mutex_init() but never
freed with pthread_mutex_destroy().  This is a potential memory leak,
depending on how pthread_mutex_t is implemented.

Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
---
 lib/librte_vhost/socket.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c
index c7f99b0..9720773 100644
--- a/lib/librte_vhost/socket.c
+++ b/lib/librte_vhost/socket.c
@@ -636,6 +636,7 @@ rte_vhost_driver_register(const char *path, uint64_t flags)
 		vsocket->reconnect = !(flags & RTE_VHOST_USER_NO_RECONNECT);
 		if (vsocket->reconnect && reconn_tid == 0) {
 			if (vhost_user_reconnect_init() < 0) {
+				pthread_mutex_destroy(&vsocket->conn_mutex);
 				free(vsocket->path);
 				free(vsocket);
 				goto out;
@@ -646,6 +647,7 @@ rte_vhost_driver_register(const char *path, uint64_t flags)
 	}
 	ret = create_unix_socket(vsocket);
 	if (ret < 0) {
+		pthread_mutex_destroy(&vsocket->conn_mutex);
 		free(vsocket->path);
 		free(vsocket);
 		goto out;
@@ -724,6 +726,7 @@ rte_vhost_driver_unregister(const char *path)
 			}
 			pthread_mutex_unlock(&vsocket->conn_mutex);
 
+			pthread_mutex_destroy(&vsocket->conn_mutex);
 			free(vsocket->path);
 			free(vsocket);
 
-- 
2.9.4

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

* Re: [dpdk-dev] [PATCH] vhost: clean up per-socket mutex
  2017-06-12 21:29 [dpdk-dev] [PATCH] vhost: clean up per-socket mutex Daniel Verkamp
@ 2017-06-14  8:19 ` Jens Freimann
  2017-07-01 23:25   ` Yuanhan Liu
  0 siblings, 1 reply; 3+ messages in thread
From: Jens Freimann @ 2017-06-14  8:19 UTC (permalink / raw)
  To: Daniel Verkamp; +Cc: dev, Maxime Coquelin (mcoqueli), Yuanhan Liu

On Mon, Jun 12, 2017 at 02:29:04PM -0700, Daniel Verkamp wrote:
> vsocket->conn_mutex was allocated with pthread_mutex_init() but never
> freed with pthread_mutex_destroy().  This is a potential memory leak,
> depending on how pthread_mutex_t is implemented.
> 
> Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
> ---
>  lib/librte_vhost/socket.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c
> index c7f99b0..9720773 100644
> --- a/lib/librte_vhost/socket.c
> +++ b/lib/librte_vhost/socket.c
> @@ -636,6 +636,7 @@ rte_vhost_driver_register(const char *path, uint64_t flags)
>  		vsocket->reconnect = !(flags & RTE_VHOST_USER_NO_RECONNECT);
>  		if (vsocket->reconnect && reconn_tid == 0) {
>  			if (vhost_user_reconnect_init() < 0) {
> +				pthread_mutex_destroy(&vsocket->conn_mutex);
>  				free(vsocket->path);
>  				free(vsocket);
>  				goto out;
> @@ -646,6 +647,7 @@ rte_vhost_driver_register(const char *path, uint64_t flags)
>  	}
>  	ret = create_unix_socket(vsocket);
>  	if (ret < 0) {
> +		pthread_mutex_destroy(&vsocket->conn_mutex);
>  		free(vsocket->path);
>  		free(vsocket);
>  		goto out;
> @@ -724,6 +726,7 @@ rte_vhost_driver_unregister(const char *path)
>  			}
>  			pthread_mutex_unlock(&vsocket->conn_mutex);
>  
> +			pthread_mutex_destroy(&vsocket->conn_mutex);

Seems like we never do it, but shouldn't we check the return value
here?

regards,
Jens 

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

* Re: [dpdk-dev] [PATCH] vhost: clean up per-socket mutex
  2017-06-14  8:19 ` Jens Freimann
@ 2017-07-01 23:25   ` Yuanhan Liu
  0 siblings, 0 replies; 3+ messages in thread
From: Yuanhan Liu @ 2017-07-01 23:25 UTC (permalink / raw)
  To: Jens Freimann; +Cc: Daniel Verkamp, dev, Maxime Coquelin (mcoqueli)

On Wed, Jun 14, 2017 at 10:19:53AM +0200, Jens Freimann wrote:
> On Mon, Jun 12, 2017 at 02:29:04PM -0700, Daniel Verkamp wrote:
> > vsocket->conn_mutex was allocated with pthread_mutex_init() but never
> > freed with pthread_mutex_destroy().  This is a potential memory leak,
> > depending on how pthread_mutex_t is implemented.
> > 
> > Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
> > ---
> >  lib/librte_vhost/socket.c | 3 +++
> >  1 file changed, 3 insertions(+)
> > 
> > diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c
> > index c7f99b0..9720773 100644
> > --- a/lib/librte_vhost/socket.c
> > +++ b/lib/librte_vhost/socket.c
> > @@ -636,6 +636,7 @@ rte_vhost_driver_register(const char *path, uint64_t flags)
> >  		vsocket->reconnect = !(flags & RTE_VHOST_USER_NO_RECONNECT);
> >  		if (vsocket->reconnect && reconn_tid == 0) {
> >  			if (vhost_user_reconnect_init() < 0) {
> > +				pthread_mutex_destroy(&vsocket->conn_mutex);
> >  				free(vsocket->path);
> >  				free(vsocket);
> >  				goto out;
> > @@ -646,6 +647,7 @@ rte_vhost_driver_register(const char *path, uint64_t flags)
> >  	}
> >  	ret = create_unix_socket(vsocket);
> >  	if (ret < 0) {
> > +		pthread_mutex_destroy(&vsocket->conn_mutex);
> >  		free(vsocket->path);
> >  		free(vsocket);
> >  		goto out;
> > @@ -724,6 +726,7 @@ rte_vhost_driver_unregister(const char *path)
> >  			}
> >  			pthread_mutex_unlock(&vsocket->conn_mutex);
> >  
> > +			pthread_mutex_destroy(&vsocket->conn_mutex);
> 
> Seems like we never do it, but shouldn't we check the return value
> here?

I think so. There are more: pthread_mutex_init/lock, etc. We probably
should make another patch to fix it. For this patch, I'd like to apply
as it is.

So applied to dpdk-next-virtio.

Thanks.

	--yliu

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

end of thread, other threads:[~2017-07-01 23:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-12 21:29 [dpdk-dev] [PATCH] vhost: clean up per-socket mutex Daniel Verkamp
2017-06-14  8:19 ` Jens Freimann
2017-07-01 23:25   ` Yuanhan Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).