[PATCH 3/3] qemu_capabilities: Resolve Coverity RESOURCE_LEAK

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

 



In function virQEMUCapsParseMachineTypesStr, VIR_STRNDUP allocates
memory for 'name' in {do,while} loop. If 'name' isn't freed before
'continue', its memory will be allocated again in the next loop.
In this case the memory allocated for 'name' in privious loop is
useless and not freed. Free it before continue this loop to fix that.

Signed-off-by: Wang Rui <moon.wangrui@xxxxxxxxxx>
---
 src/qemu/qemu_capabilities.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index ce899f2..4a540ee 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -433,8 +433,10 @@ virQEMUCapsParseMachineTypesStr(const char *output,
 
         if ((t = strstr(p, "(alias of ")) && (!next || t < next)) {
             p = t + strlen("(alias of ");
-            if (!(t = strchr(p, ')')) || (next && t >= next))
+            if (!(t = strchr(p, ')')) || (next && t >= next)) {
+                VIR_FREE(name);
                 continue;
+            }
 
             if (VIR_STRNDUP(canonical, p, t - p) < 0) {
                 VIR_FREE(name);
-- 
1.7.12.4


--
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]