[libvirt PATCH 0/2] Coverity diaries

two minor bug fixes Ján Tomko (2): cmdList: mark title as autofree nss: findLease: do not leak path tools/nss/libvirt_nss.c | 4 +++- tools/virsh-domain-monitor.c | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) -- 2.29.2

Fixes the (im)possible memory leak on vshTableRowAppend failure. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tools/virsh-domain-monitor.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 897339b6f9..fcbc2fe9f0 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -1961,7 +1961,6 @@ cmdList(vshControl *ctl, const vshCmd *cmd) bool optName = vshCommandOptBool(cmd, "name"); bool optID = vshCommandOptBool(cmd, "id"); size_t i; - char *title; char uuid[VIR_UUID_STRING_BUFLEN]; int state; bool ret = false; @@ -2044,6 +2043,8 @@ cmdList(vshControl *ctl, const vshCmd *cmd) state = -2; if (optTitle) { + g_autofree char *title = NULL; + if (!(title = virshGetDomainDescription(ctl, dom, true, 0))) goto cleanup; if (vshTableRowAppend(table, id_buf, @@ -2052,7 +2053,6 @@ cmdList(vshControl *ctl, const vshCmd *cmd) : virshDomainStateToString(state), title, NULL) < 0) goto cleanup; - VIR_FREE(title); } else { if (vshTableRowAppend(table, id_buf, virDomainGetName(dom), -- 2.29.2

We still check for realloc's return value in the nss module. Free the path in case it fails before jumping to cleanup. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tools/nss/libvirt_nss.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/nss/libvirt_nss.c b/tools/nss/libvirt_nss.c index b021efc3c9..87a731da79 100644 --- a/tools/nss/libvirt_nss.c +++ b/tools/nss/libvirt_nss.c @@ -138,8 +138,10 @@ findLease(const char *name, goto cleanup; tmpLease = realloc(leaseFiles, sizeof(char *) * (nleaseFiles + 1)); - if (!tmpLease) + if (!tmpLease) { + free(path); goto cleanup; + } leaseFiles = tmpLease; leaseFiles[nleaseFiles++] = path; #if defined(LIBVIRT_NSS_GUEST) -- 2.29.2

On 3/15/21 4:46 PM, Ján Tomko wrote:
two minor bug fixes
Ján Tomko (2): cmdList: mark title as autofree nss: findLease: do not leak path
tools/nss/libvirt_nss.c | 4 +++- tools/virsh-domain-monitor.c | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-)
Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Michal
participants (2)
-
Ján Tomko
-
Michal Privoznik