From 91490583f3cc8613159008502decf2f1481508fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 12 Sep 2019 16:25:09 +0400 Subject: [PATCH] migration: fix vmdesc leak on vmstate_save() error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marc-André Lureau Message-Id: <20190912122514.22504-2-marcandre.lureau@redhat.com> Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Daniel P. Berrangé Signed-off-by: Dr. David Alan Gilbert --- migration/qjson.h | 2 ++ migration/savevm.c | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/migration/qjson.h b/migration/qjson.h index 41664f2d71..1786bb5864 100644 --- a/migration/qjson.h +++ b/migration/qjson.h @@ -24,4 +24,6 @@ void json_start_object(QJSON *json, const char *name); const char *qjson_get_str(QJSON *json); void qjson_finish(QJSON *json); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(QJSON, qjson_destroy) + #endif /* QEMU_QJSON_H */ diff --git a/migration/savevm.c b/migration/savevm.c index ee06f91d42..bb9462a54d 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1314,7 +1314,7 @@ int qemu_savevm_state_complete_precopy_non_iterable(QEMUFile *f, bool in_postcopy, bool inactivate_disks) { - QJSON *vmdesc; + g_autoptr(QJSON) vmdesc = NULL; int vmdesc_len; SaveStateEntry *se; int ret; @@ -1375,7 +1375,6 @@ int qemu_savevm_state_complete_precopy_non_iterable(QEMUFile *f, qemu_put_be32(f, vmdesc_len); qemu_put_buffer(f, (uint8_t *)qjson_get_str(vmdesc), vmdesc_len); } - qjson_destroy(vmdesc); return 0; }