[libvirt] [libvirt-php][PATCH 3/3] Revisit some VIRT_RETURN_STRING

Neal Gompa ngompa13 at gmail.com
Tue Apr 19 14:29:43 UTC 2016


On Tue, Apr 19, 2016 at 9:46 AM, Michal Privoznik <mprivozn at redhat.com> wrote:
> This macro sets return value and returns immediately. This can
> lead to a possible leak because any free() that would come
> afterwards is in fact never called.
>
> Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
> ---
>  src/libvirt-php.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/src/libvirt-php.c b/src/libvirt-php.c
> index fb0679b..6f6e137 100644
> --- a/src/libvirt-php.c
> +++ b/src/libvirt-php.c
> @@ -4307,7 +4307,8 @@ PHP_FUNCTION(libvirt_domain_qemu_agent_command)
>         ret = virDomainQemuAgentCommand(domain->domain, cmd, timeout, flags);
>         if (ret == NULL) RETURN_FALSE;
>
> -       VIRT_RETURN_STRING(ret);
> +       VIRT_RETVAL_STRING(ret);
> +       free(ret);
>  }
>
>  /*
> @@ -6691,7 +6692,7 @@ PHP_FUNCTION(libvirt_domain_memory_peek)
>      buff=(char *)emalloc(size);
>      retval=virDomainMemoryPeek(domain->domain,start,size,buff,flags);
>      if (retval != 0) RETURN_FALSE;
> -    VIRT_RETURN_STRINGL(buff, size);
> +    VIRT_RETVAL_STRINGL(buff, size);
>      efree(buff);
>  }
>
> @@ -7872,7 +7873,8 @@ PHP_FUNCTION(libvirt_storagevolume_get_path)
>      DPRINTF("%s: virStorageVolGetPath(%p) returned %s\n", PHPFUNC, volume->volume, retval);
>      if (retval == NULL) RETURN_FALSE;
>
> -    VIRT_RETURN_STRING(retval);
> +    VIRT_RETVAL_STRING(retval);
> +    free(retval);
>  }
>
>  /*
> @@ -9506,7 +9508,8 @@ PHP_FUNCTION(libvirt_network_get_bridge)
>          RETURN_FALSE;
>      }
>
> -    VIRT_RETURN_STRING(name);
> +    VIRT_RETVAL_STRING(name);
> +    free(name);
>  }
>
>  /*
> --
> 2.7.3
>

Applied locally and tested. Works okay for me. :)



-- 
真実はいつも一つ!/ Always, there's only one truth!




More information about the libvir-list mailing list