Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
src/libvirt-connection.c | 2 ++
src/libvirt-php.c | 11 +++++++++--
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/src/libvirt-connection.c b/src/libvirt-connection.c
index 086cd57..9e70031 100644
--- a/src/libvirt-connection.c
+++ b/src/libvirt-connection.c
@@ -404,6 +404,7 @@ PHP_FUNCTION(libvirt_connect_get_nic_models)
char cmd[4096] = { 0 };
char tmp2[16] = { 0 };
snprintf(cmd, sizeof(cmd), "%s -net nic,model=? 2>&1", tmp);
+ VIR_FREE(tmp);
FILE *fp = popen(cmd, "r");
if (fp == NULL)
@@ -475,6 +476,7 @@ PHP_FUNCTION(libvirt_connect_get_soundhw_models)
char cmd[4096] = { 0 };
snprintf(cmd, sizeof(cmd), "%s -soundhw help 2>&1", tmp);
+ VIR_FREE(tmp);
FILE *fp = popen(cmd, "r");
if (fp == NULL)
diff --git a/src/libvirt-php.c b/src/libvirt-php.c
index 5ec6e60..cf8fd7f 100644
--- a/src/libvirt-php.c
+++ b/src/libvirt-php.c
@@ -2277,6 +2277,7 @@ char *installation_get_xml(virConnectPtr conn, char *name, int memMB,
{
int i;
char *xml = NULL;
+ char *emulator = NULL;
char disks_xml[16384] = { 0 };
char networks_xml[16384] = { 0 };
char features[128] = { 0 };
@@ -2304,6 +2305,11 @@ char *installation_get_xml(virConnectPtr conn, char *name, int memMB,
DPRINTF("%s: No architecture defined, got host arch of '%s'\n", __FUNCTION__, arch);
}
+ if (!(emulator = connection_get_emulator(conn, arch TSRMLS_CC))) {
+ DPRINTF("%s: Cannot get emulator\n", __FUNCTION__);
+ return NULL;
+ }
+
if (iso_image && access(iso_image, R_OK) != 0) {
DPRINTF("%s: Installation image %s doesn't exist\n", __FUNCTION__, iso_image);
return NULL;
@@ -2370,7 +2376,7 @@ char *installation_get_xml(virConnectPtr conn, char *name, int memMB,
"</domain>",
type, name, memMB * 1024, maxmemMB * 1024, uuid, arch, features,
(domain_flags & DOMAIN_FLAG_CLOCK_LOCALTIME ? "localtime" : "utc"),
- vCpus, connection_get_emulator(conn, arch TSRMLS_CC), disks_xml,
+ vCpus, emulator, disks_xml,
iso_image, networks_xml,
(domain_flags & DOMAIN_FLAG_SOUND_AC97 ? "<sound model='ac97'/>\n" : ""));
} else {
@@ -2409,11 +2415,12 @@ char *installation_get_xml(virConnectPtr conn, char *name, int memMB,
"</domain>",
type, name, memMB * 1024, maxmemMB * 1024, uuid, arch, features,
(domain_flags & DOMAIN_FLAG_CLOCK_LOCALTIME ? "localtime" : "utc"),
- vCpus, connection_get_emulator(conn, arch TSRMLS_CC), disks_xml,
+ vCpus, emulator, disks_xml,
networks_xml,
(domain_flags & DOMAIN_FLAG_SOUND_AC97 ? "<sound model='ac97'/>\n" : ""));
}
+ VIR_FREE(emulator);
VIR_FREE(tmp);
VIR_FREE(arch);
if (rv < 0)
--
2.13.6
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
On Mon, Dec 11, 2017 at 07:34:59AM +0100, Michal Privoznik wrote:
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
> src/libvirt-connection.c | 2 ++
> src/libvirt-php.c | 11 +++++++++--
> 2 files changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/src/libvirt-connection.c b/src/libvirt-connection.c
> index 086cd57..9e70031 100644
> --- a/src/libvirt-connection.c
> +++ b/src/libvirt-connection.c
> @@ -404,6 +404,7 @@ PHP_FUNCTION(libvirt_connect_get_nic_models)
> char cmd[4096] = { 0 };
> char tmp2[16] = { 0 };
> snprintf(cmd, sizeof(cmd), "%s -net nic,model=? 2>&1", tmp);
> + VIR_FREE(tmp);
>
> FILE *fp = popen(cmd, "r");
> if (fp == NULL)
> @@ -475,6 +476,7 @@ PHP_FUNCTION(libvirt_connect_get_soundhw_models)
>
> char cmd[4096] = { 0 };
> snprintf(cmd, sizeof(cmd), "%s -soundhw help 2>&1", tmp);
> + VIR_FREE(tmp);
>
^These two are unrelated to the patch, either put them in a separate patch or
squash patches 2,4,5/5 into a single patch.
Reviewed-by: Erik Skultety <eskultet@redhat.com>
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
On 12/11/2017 09:02 AM, Erik Skultety wrote:
> On Mon, Dec 11, 2017 at 07:34:59AM +0100, Michal Privoznik wrote:
>> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
>> ---
>> src/libvirt-connection.c | 2 ++
>> src/libvirt-php.c | 11 +++++++++--
>> 2 files changed, 11 insertions(+), 2 deletions(-)
>>
>> diff --git a/src/libvirt-connection.c b/src/libvirt-connection.c
>> index 086cd57..9e70031 100644
>> --- a/src/libvirt-connection.c
>> +++ b/src/libvirt-connection.c
>> @@ -404,6 +404,7 @@ PHP_FUNCTION(libvirt_connect_get_nic_models)
>> char cmd[4096] = { 0 };
>> char tmp2[16] = { 0 };
>> snprintf(cmd, sizeof(cmd), "%s -net nic,model=? 2>&1", tmp);
>> + VIR_FREE(tmp);
>>
>> FILE *fp = popen(cmd, "r");
>> if (fp == NULL)
>> @@ -475,6 +476,7 @@ PHP_FUNCTION(libvirt_connect_get_soundhw_models)
>>
>> char cmd[4096] = { 0 };
>> snprintf(cmd, sizeof(cmd), "%s -soundhw help 2>&1", tmp);
>> + VIR_FREE(tmp);
>>
>
>
> ^These two are unrelated to the patch, either put them in a separate patch or
> squash patches 2,4,5/5 into a single patch.
Not really. The commit message says "Don't leak connection_get_emulator
retval". Now, if you view this patch with wider context (say -U20),
you'll see that both @tmp variables hold return value of the function.
Agreed that this patch might be not that clean, but the source code is
not that clean either :-) that ship has sailed a long time ago :-(.
Michal
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
© 2016 - 2025 Red Hat, Inc.