mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-21 19:02:25 +00:00
virsh: avoid memory leak on cmdVolCreateAs
* tools/virsh.c: fix memory leak on cmdVolCreateAs function. * Detected in valgrind run: ==4746== ==4746== 48 (40 direct, 8 indirect) bytes in 1 blocks are definitely lost in loss record 26 of 52 ==4746== at 0x4A04A28: calloc (vg_replace_malloc.c:467) ==4746== by 0x4C76E51: virAlloc (memory.c:101) ==4746== by 0x4CD9418: virGetStoragePool (datatypes.c:592) ==4746== by 0x4D21367: remoteStoragePoolLookupByName (remote_driver.c:4126) ==4746== by 0x4CE42B0: virStoragePoolLookupByName (libvirt.c:10232) ==4746== by 0x40C276: vshCommandOptPoolBy (virsh.c:13660) ==4746== by 0x40CA37: cmdVolCreateAs (virsh.c:8094) ==4746== by 0x412AF2: vshCommandRun (virsh.c:13770) ==4746== by 0x422F11: main (virsh.c:15127) ==4746== ==4746== 1,011 bytes in 1 blocks are definitely lost in loss record 45 of 52 ==4746== at 0x4A05FDE: malloc (vg_replace_malloc.c:236) ==4746== by 0x4A06167: realloc (vg_replace_malloc.c:525) ==4746== by 0x4C76ECB: virReallocN (memory.c:161) ==4746== by 0x4C60319: virBufferGrow (buf.c:72) ==4746== by 0x4C606AA: virBufferAdd (buf.c:106) ==4746== by 0x40CB37: cmdVolCreateAs (virsh.c:8118) ==4746== by 0x412AF2: vshCommandRun (virsh.c:13770) ==4746== by 0x422F11: main (virsh.c:15127) ==4746== ==4746== LEAK SUMMARY: ==4746== definitely lost: 1,051 bytes in 2 blocks ==4746== indirectly lost: 8 bytes in 1 blocks ==4746== possibly lost: 0 bytes in 0 blocks ==4746== still reachable: 390,767 bytes in 1,373 blocks ==4746== suppressed: 0 bytes in 0 blocks * How to reproduce? % valgrind -v --leak-check=full virsh vol-create-as default foo.img 10M \ --allocation 0 --format qcow2 --backing-vol bar.img Notes: bar.img doesn't exist. Signed-off-by: Alex Jia <ajia@redhat.com>
This commit is contained in:
parent
7bc1c5cefe
commit
59d4b170fc
@ -8205,13 +8205,13 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
|
||||
}
|
||||
if (snapVol == NULL) {
|
||||
vshError(ctl, _("failed to get vol '%s'"), snapshotStrVol);
|
||||
return false;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
char *snapshotStrVolPath;
|
||||
if ((snapshotStrVolPath = virStorageVolGetPath(snapVol)) == NULL) {
|
||||
virStorageVolFree(snapVol);
|
||||
return false;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* Create XML for the backing store */
|
||||
@ -8230,7 +8230,7 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
|
||||
|
||||
if (virBufferError(&buf)) {
|
||||
vshPrint(ctl, "%s", _("Failed to allocate XML buffer"));
|
||||
return false;
|
||||
goto cleanup;
|
||||
}
|
||||
xml = virBufferContentAndReset(&buf);
|
||||
vol = virStorageVolCreateXML(pool, xml, 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user