diff --git a/tools/virsh.c b/tools/virsh.c
index dc9d44c017..5fdbbe51d0 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -7140,11 +7140,9 @@ cleanup:
     return ret;
 
 no_memory:
-    VIR_FREE(list);
-    VIR_FREE(buffer);
     vshError(ctl, "%s", _("Out of memory"));
     ret = FALSE;
-    return ret;
+    goto cleanup;
 }
 
 /* Common code for the edit / net-edit / pool-edit functions which follow. */