[libvirt] [PATCH 1/4] tests: plug memory leaks
Laine Stump
laine at laine.org
Fri Dec 10 20:07:07 UTC 2010
On 12/10/2010 02:17 PM, Eric Blake wrote:
> * tests/qemuxml2argvtest.c (testCompareXMLToArgvFiles): Don't
> allocate, since we don't use virDomainChrDefFree.
> ---
>
> Makes it easier to run valgrind on qemuxml2argv to spot the leaks
> in libvirt proper.
>
> tests/qemuxml2argvtest.c | 3 +--
> 1 files changed, 1 insertions(+), 2 deletions(-)
>
> diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
> index db2d006..5387432 100644
> --- a/tests/qemuxml2argvtest.c
> +++ b/tests/qemuxml2argvtest.c
> @@ -86,8 +86,7 @@ static int testCompareXMLToArgvFiles(const char *xml,
> monitor_chr.type = VIR_DOMAIN_CHR_TYPE_UNIX;
> monitor_chr.data.nix.path = (char *)"/tmp/test-monitor";
> monitor_chr.data.nix.listen = 1;
> - if (!(monitor_chr.info.alias = strdup("monitor")))
> - goto fail;
> + monitor_chr.info.alias = (char *)"monitor";
>
> flags = QEMUD_CMD_FLAG_VNC_COLON |
> QEMUD_CMD_FLAG_NO_REBOOT |
Well, to be totally safe and correct with this, you might instead want
to create a function virDomainChrDefClear(), derived from
virDomainChrDefFree(), and call that when you're done with monitor_chr
(or just ALLOC monitor_chr instead of putting it on the stack, then call
virDomainChrDefFree().
I'm okay with this fix anyway, as it stays within the spirit of the
original code, and technically does fix the problem, so ACK.
More information about the libvir-list
mailing list