[libvirt] [libvirt-php][PATCH 2/5] src: Don't leak @uuid in libvirt_nwfilter_get_uuid_string

Michal Privoznik posted 5 patches 7 years, 5 months ago
[libvirt] [libvirt-php][PATCH 2/5] src: Don't leak @uuid in libvirt_nwfilter_get_uuid_string
Posted by Michal Privoznik 7 years, 5 months ago
VIRT_RETURN_STRING() does immediate return. Therefore,
efree(uuid) is never called and thus leaked. Moreover, there's no
reason for dynamically allocated uuid buffer (in contrast to our
misuse of large static buffers).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/libvirt-nwfilter.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/src/libvirt-nwfilter.c b/src/libvirt-nwfilter.c
index cd082a5..1b5dbdc 100644
--- a/src/libvirt-nwfilter.c
+++ b/src/libvirt-nwfilter.c
@@ -145,12 +145,11 @@ PHP_FUNCTION(libvirt_nwfilter_get_uuid_string)
 {
     php_libvirt_nwfilter *nwfilter = NULL;
     zval *znwfilter;
-    char *uuid = NULL;
+    char uuid[VIR_UUID_STRING_BUFLEN];
     int ret = -1;
 
     GET_NWFILTER_FROM_ARGS("r", &znwfilter);
 
-    uuid = (char *) emalloc(VIR_UUID_STRING_BUFLEN);
     ret = virNWFilterGetUUIDString(nwfilter->nwfilter, uuid);
 
     DPRINTF("%s: virNWFilterGetUUIDString(%p) returned %d (%s)\n", PHPFUNC,
@@ -160,7 +159,6 @@ PHP_FUNCTION(libvirt_nwfilter_get_uuid_string)
         RETURN_FALSE;
 
     VIRT_RETURN_STRING(uuid);
-    efree(uuid);
 }
 
 /*
-- 
2.13.6

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-php][PATCH 2/5] src: Don't leak @uuid in libvirt_nwfilter_get_uuid_string
Posted by Erik Skultety 7 years, 5 months ago
On Mon, Dec 11, 2017 at 07:34:56AM +0100, Michal Privoznik wrote:
> VIRT_RETURN_STRING() does immediate return. Therefore,
> efree(uuid) is never called and thus leaked. Moreover, there's no
> reason for dynamically allocated uuid buffer (in contrast to our
> misuse of large static buffers).
>
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---

Reviewed-by: Erik Skultety <eskultet@redhat.com>

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list