All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] libxc: Fix CID 1351228 resource leak
@ 2016-02-10  9:09 Harmandeep Kaur
  2016-02-10  9:32 ` Dario Faggioli
  0 siblings, 1 reply; 4+ messages in thread
From: Harmandeep Kaur @ 2016-02-10  9:09 UTC (permalink / raw)
  To: xen-devel
  Cc: wei.liu2, ian.campbell, stefano.stabellini, dario.faggioli,
	ian.jackson, Harmandeep Kaur

Signed-off-by: Harmandeep Kaur <write.harmandeep@gmail.com>
---
 tools/libxc/xc_tbuf.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/libxc/xc_tbuf.c b/tools/libxc/xc_tbuf.c
index 695939a..f06f566 100644
--- a/tools/libxc/xc_tbuf.c
+++ b/tools/libxc/xc_tbuf.c
@@ -70,9 +70,13 @@ int xc_tbuf_get_size(xc_interface *xch, unsigned long *size)
                     sysctl.u.tbuf_op.buffer_mfn);
 
     if ( t_info == NULL || t_info->tbuf_size == 0 )
+    {
+        xenforeignmemory_unmap(xch->fmem, t_info, 0);
         return -1;
+    }
 
     *size = t_info->tbuf_size;
+    xenforeignmemory_unmap(xch->fmem, t_info, *size);
 
     return 0;
 }
-- 
2.5.0

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

* Re: [PATCH] libxc: Fix CID 1351228 resource leak
  2016-02-10  9:09 [PATCH] libxc: Fix CID 1351228 resource leak Harmandeep Kaur
@ 2016-02-10  9:32 ` Dario Faggioli
  2016-02-10 11:14   ` Ian Jackson
  0 siblings, 1 reply; 4+ messages in thread
From: Dario Faggioli @ 2016-02-10  9:32 UTC (permalink / raw)
  To: Harmandeep Kaur, xen-devel
  Cc: wei.liu2, ian.jackson, ian.campbell, stefano.stabellini


[-- Attachment #1.1: Type: text/plain, Size: 1248 bytes --]

On Wed, 2016-02-10 at 14:39 +0530, Harmandeep Kaur wrote:
>
What I just said about the other patch ("libxc: Fix CID 1351225
resource leak") applies here as well, of course. :-)

About the code...

> --- a/tools/libxc/xc_tbuf.c
> +++ b/tools/libxc/xc_tbuf.c
> @@ -70,9 +70,13 @@ int xc_tbuf_get_size(xc_interface *xch, unsigned
> long *size)
>                      sysctl.u.tbuf_op.buffer_mfn);
>  
>      if ( t_info == NULL || t_info->tbuf_size == 0 )
> +    {
> +        xenforeignmemory_unmap(xch->fmem, t_info, 0);
>          return -1;
> +    }
>  
>      *size = t_info->tbuf_size;
> +    xenforeignmemory_unmap(xch->fmem, t_info, *size);
>  
I think you can arrange for only calling the unmapping function once,
i.e., put the unmap call in a place where (after a slight
reorganization of the rest of the code as well) it can be common to
both the success and error path.

Regards,
Dario
-- 
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)


[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

[-- Attachment #2: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

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

* Re: [PATCH] libxc: Fix CID 1351228 resource leak
  2016-02-10  9:32 ` Dario Faggioli
@ 2016-02-10 11:14   ` Ian Jackson
  2016-02-10 14:09     ` Ian Campbell
  0 siblings, 1 reply; 4+ messages in thread
From: Ian Jackson @ 2016-02-10 11:14 UTC (permalink / raw)
  To: Dario Faggioli
  Cc: xen-devel, ian.campbell, wei.liu2, Harmandeep Kaur, stefano.stabellini

Dario Faggioli writes ("Re: [PATCH] libxc: Fix CID 1351228 resource leak"):
> On Wed, 2016-02-10 at 14:39 +0530, Harmandeep Kaur wrote:
> >
> What I just said about the other patch ("libxc: Fix CID 1351225
> resource leak") applies here as well, of course. :-)
> 
> About the code...
...
> >      if ( t_info == NULL || t_info->tbuf_size == 0 )
> > +    {
> > +        xenforeignmemory_unmap(xch->fmem, t_info, 0);
> >          return -1;
> > +    }
> >  
> >      *size = t_info->tbuf_size;
> > +    xenforeignmemory_unmap(xch->fmem, t_info, *size);
...
> I think you can arrange for only calling the unmapping function once,
> i.e., put the unmap call in a place where (after a slight
> reorganization of the rest of the code as well) it can be common to
> both the success and error path.

Indeed.  See tools/libxl/CODING_STYLE.

Ian.

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

* Re: [PATCH] libxc: Fix CID 1351228 resource leak
  2016-02-10 11:14   ` Ian Jackson
@ 2016-02-10 14:09     ` Ian Campbell
  0 siblings, 0 replies; 4+ messages in thread
From: Ian Campbell @ 2016-02-10 14:09 UTC (permalink / raw)
  To: Ian Jackson, Dario Faggioli
  Cc: xen-devel, wei.liu2, Harmandeep Kaur, stefano.stabellini

On Wed, 2016-02-10 at 11:14 +0000, Ian Jackson wrote:
> Dario Faggioli writes ("Re: [PATCH] libxc: Fix CID 1351228 resource
> leak"):
> > On Wed, 2016-02-10 at 14:39 +0530, Harmandeep Kaur wrote:
> > > 
> > What I just said about the other patch ("libxc: Fix CID 1351225
> > resource leak") applies here as well, of course. :-)
> > 
> > About the code...
> ...
> > >      if ( t_info == NULL || t_info->tbuf_size == 0 )
> > > +    {
> > > +        xenforeignmemory_unmap(xch->fmem, t_info, 0);
> > >          return -1;
> > > +    }
> > >  
> > >      *size = t_info->tbuf_size;
> > > +    xenforeignmemory_unmap(xch->fmem, t_info, *size);
> ...
> > I think you can arrange for only calling the unmapping function once,
> > i.e., put the unmap call in a place where (after a slight
> > reorganization of the rest of the code as well) it can be common to
> > both the success and error path.
> 
> Indeed.  See tools/libxl/CODING_STYLE.

The code being modified here is in libxc, so strictly speaking this doesn't
apply. However it is still a good principal to obey.

Ian.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

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

end of thread, other threads:[~2016-02-10 14:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-10  9:09 [PATCH] libxc: Fix CID 1351228 resource leak Harmandeep Kaur
2016-02-10  9:32 ` Dario Faggioli
2016-02-10 11:14   ` Ian Jackson
2016-02-10 14:09     ` Ian Campbell

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.