Skip to contentSkip to conversation

libxc: Fix CID 1351228 resource leak

PATCH In review Harmandeep Kaur 4 participants 4 messages Feb 10, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxc: Fix CID 1351228 resource leak

---
 tools/libxc/xc_tbuf.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/libxc/xc_tbuf.c +4 -0
index 695939a..f06f566 100644
@@ -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;
 }
Signature · 1 line
2.5.0
#1 lore raw
Quoted 1 line · Harmandeep Kaur

What I just said about the other patch ("libxc: Fix CID 1351225 resource leak") applies here as well, of course. :-)

About the code...

Quoted 7 lines
tools/libxc/xc_tbuf.c +0 -0
@@ -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 )

Quoted 8 lines

+    {
+        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

Signature · 4 lines
<<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)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#2 lore raw

Dario Faggioli writes ("Re: [PATCH] libxc: Fix CID 1351228 resource leak"):

Quoted 6 lines · Harmandeep Kaur
Quoted 1 line

What I just said about the other patch ("libxc: Fix CID 1351225 resource leak") applies here as well, of course. :-)

About the code...

...

Quoted 8 lines
Quoted 8 lines

     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);

...

Quoted 4 lines

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.

#3 lore raw
Quoted 17 lines · Ian Jackson

Dario Faggioli writes ("Re: [PATCH] libxc: Fix CID 1351228 resource leak"):

Quoted 6 lines · Harmandeep Kaur
Quoted 1 line

What I just said about the other patch ("libxc: Fix CID 1351225 resource leak") applies here as well, of course. :-)

About the code...

...

Quoted 8 lines
Quoted 8 lines

     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);

Quoted 7 lines

...

Quoted 4 lines

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
[email protected]
http://lists.xen.org/xen-devel