On 09/02/2011 02:41 AM, Eric Blake wrote:
On 09/01/2011 11:12 AM, Alex Jia wrote:
> * tools/virsh.c: fix memory leak on cmdVolCreateAs function.
>
> % 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(a)redhat.com>
> ---
> tools/virsh.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/tools/virsh.c b/tools/virsh.c
> index f9bcd2c..44c2f1c 100644
> --- a/tools/virsh.c
> +++ b/tools/virsh.c
> @@ -8166,7 +8166,7 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
> }
> if (snapVol == NULL) {
> vshError(ctl, _("failed to get vol '%s'"),
> snapshotStrVol);
> - return false;
> + goto cleanup;
Incomplete. There were a couple other early returns in this function.
I'm pushing with this squashed in:
diff --git i/tools/virsh.c w/tools/virsh.c
index 7453995..5c5343e 100644
--- i/tools/virsh.c
+++ w/tools/virsh.c
@@ -8211,7 +8211,7 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
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);
Yeah, should release memory before returning.
Thanks,
Alex