From: John Ferlan Date: Thu, 20 Dec 2018 21:27:40 +0000 (-0500) Subject: security: Resolve possible memory leak X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=458b952beefa6218d75964d1c43da60ca9d60d07;p=libvirt.git security: Resolve possible memory leak If virSecuritySELinuxRestoreFileLabel returns 0 or -1 too soon, then the @newpath will be leaked. Suggested-by: Michal Privoznik Signed-off-by: John Ferlan Reviewed-by: Ján Tomko --- diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c index 4de8b6f9cd..f3690a4cb1 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -1477,10 +1477,12 @@ virSecuritySELinuxRestoreFileLabel(virSecurityManagerPtr mgr, goto cleanup; } - if ((rc = virSecuritySELinuxTransactionAppend(path, NULL, false, true)) < 0) - return -1; - else if (rc > 0) - return 0; + if ((rc = virSecuritySELinuxTransactionAppend(path, NULL, false, true)) < 0) { + goto cleanup; + } else if (rc > 0) { + ret = 0; + goto cleanup; + } if (recall) { if ((rc = virSecuritySELinuxRecallLabel(newpath, &fcon)) < 0) {