[libvirt] [libvirt-php][PATCH] Don't leak @mime in libvirt_domain_get_screenshot_api

Michal Privoznik mprivozn at redhat.com
Thu Sep 8 07:55:33 UTC 2016


When getting a screenshot of a domain via virDomainScreenshot()
the MIME type of a image is returned as a string which needs to
be freed by caller. However, we are not doing that anywhere.

==24748== 48 bytes in 2 blocks are definitely lost in loss record 123 of 171
==24748==    at 0x4C29F80: malloc (vg_replace_malloc.c:296)
==24748==    by 0x90674AB: xdr_string (xdr.c:790)
==24748==    by 0xCD3AF1D: xdr_remote_nonnull_string (in /usr/lib64/libvirt.so.0.2003.0)
==24748==    by 0x9067B34: xdr_reference (xdr_ref.c:84)
==24748==    by 0x9067C50: xdr_pointer (xdr_ref.c:135)
==24748==    by 0xCD3B284: xdr_remote_string (in /usr/lib64/libvirt.so.0.2003.0)
==24748==    by 0xCD3D288: xdr_remote_domain_screenshot_ret (in /usr/lib64/libvirt.so.0.2003.0)
==24748==    by 0xCD5168E: virNetMessageDecodePayload (in /usr/lib64/libvirt.so.0.2003.0)
==24748==    by 0xCD47E91: virNetClientProgramCall (in /usr/lib64/libvirt.so.0.2003.0)
==24748==    by 0xCD1EBD3: callFull.isra.3 (in /usr/lib64/libvirt.so.0.2003.0)
==24748==    by 0xCD29973: remoteDomainScreenshot (in /usr/lib64/libvirt.so.0.2003.0)
==24748==    by 0xCCDC24C: virDomainScreenshot (in /usr/lib64/libvirt.so.0.2003.0)

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---

Pushed under php-autopush rule.

 src/libvirt-php.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/libvirt-php.c b/src/libvirt-php.c
index 8edcb10..57ef1a0 100644
--- a/src/libvirt-php.c
+++ b/src/libvirt-php.c
@@ -4767,8 +4767,10 @@ PHP_FUNCTION(libvirt_domain_get_screenshot_api)
     }
 
 #ifndef EXTWIN
-    if (mkstemp(file) == 0)
+    if (mkstemp(file) == 0) {
+        free(mime);
         RETURN_FALSE;
+    }
 #endif
 
     if ((fd = open(file, O_WRONLY|O_CREAT|O_EXCL, 0666)) < 0) {
@@ -4776,6 +4778,7 @@ PHP_FUNCTION(libvirt_domain_get_screenshot_api)
             (fd = open(file, O_WRONLY|O_TRUNC, 0666)) < 0) {
             virStreamFree(st);
             set_error_if_unset("Cannot get create file to save domain screenshot" TSRMLS_CC);
+            free(mime);
             RETURN_FALSE;
         }
     }
@@ -4783,6 +4786,7 @@ PHP_FUNCTION(libvirt_domain_get_screenshot_api)
     if (virStreamRecvAll(st, streamSink, &fd) < 0) {
         virStreamFree(st);
         set_error_if_unset("Cannot receive screenshot data" TSRMLS_CC);
+        free(mime);
         RETURN_FALSE;
     }
 
@@ -4791,6 +4795,7 @@ PHP_FUNCTION(libvirt_domain_get_screenshot_api)
     if (virStreamFinish(st) < 0) {
         virStreamFree(st);
         set_error_if_unset("Cannot close stream for domain" TSRMLS_CC);
+        free(mime);
         RETURN_FALSE;
     }
 
@@ -4816,6 +4821,8 @@ PHP_FUNCTION(libvirt_domain_get_screenshot_api)
         VIRT_ADD_ASSOC_STRING(return_value, "file", file);
         VIRT_ADD_ASSOC_STRING(return_value, "mime", mime);
     }
+
+    free(mime);
 }
 
 /*
-- 
2.8.4




More information about the libvir-list mailing list