Re: [PATCH 2/4] tests: Fix leaks in commandtest

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> >      free(virtTestLogContentAndReset());
> >      cmd = virCommandNew(abs_builddir "/commandhelper-doesnotexist");
> > -    if (virCommandRun(cmd, NULL) == 0)
> > +    if (!cmd || virCommandRun(cmd, NULL) == 0)
> 
> The API explicitly does *not* require you to check
> !cmd after virCommandNew. virCommandRun() and other
> APis will check that for you and return ENOMEM.

That was my suspicion too but then I looked at virCommandRun implementation
and saw this:

    if (!cmd || cmd->has_error == -1) {
        virCommandError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("invalid use of command API"));
        return -1;
    }
    if (cmd->has_error == ENOMEM) {
        virReportOOMError();
        return -1;
    }

That is, if virCommandNew() returns NULL for either reason, by running
virCommandRun() on it, the original error (probably OOM) gets overwritten by
an internal error.

Jirka

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


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]