softmmu: Fix dirtylimit memory leak

Fix memory leak in hmp_info_vcpu_dirty_limit,use g_autoptr
to handle memory deallocation.

Signed-off-by: alloc.young <alloc.young@outlook.com>
Reviewed-by: Hyman Huang <yong.huang@smartx.com>
Message-Id: <SA1PR11MB6760B9AB7EAFBDAFB524ED06F5E3A@SA1PR11MB6760.namprd11.prod.outlook.com>
Signed-off-by: Hyman Huang <yong.huang@smartx.com>
This commit is contained in:
alloc.young 2023-08-25 10:31:20 +08:00 committed by Hyman Huang
parent f5fe7c17ac
commit 58b4def2a2

View File

@ -653,7 +653,8 @@ struct DirtyLimitInfoList *qmp_query_vcpu_dirty_limit(Error **errp)
void hmp_info_vcpu_dirty_limit(Monitor *mon, const QDict *qdict) void hmp_info_vcpu_dirty_limit(Monitor *mon, const QDict *qdict)
{ {
DirtyLimitInfoList *limit, *head, *info = NULL; DirtyLimitInfoList *info;
g_autoptr(DirtyLimitInfoList) head = NULL;
Error *err = NULL; Error *err = NULL;
if (!dirtylimit_in_service()) { if (!dirtylimit_in_service()) {
@ -661,20 +662,17 @@ void hmp_info_vcpu_dirty_limit(Monitor *mon, const QDict *qdict)
return; return;
} }
info = qmp_query_vcpu_dirty_limit(&err); head = qmp_query_vcpu_dirty_limit(&err);
if (err) { if (err) {
hmp_handle_error(mon, err); hmp_handle_error(mon, err);
return; return;
} }
head = info; for (info = head; info != NULL; info = info->next) {
for (limit = head; limit != NULL; limit = limit->next) {
monitor_printf(mon, "vcpu[%"PRIi64"], limit rate %"PRIi64 " (MB/s)," monitor_printf(mon, "vcpu[%"PRIi64"], limit rate %"PRIi64 " (MB/s),"
" current rate %"PRIi64 " (MB/s)\n", " current rate %"PRIi64 " (MB/s)\n",
limit->value->cpu_index, info->value->cpu_index,
limit->value->limit_rate, info->value->limit_rate,
limit->value->current_rate); info->value->current_rate);
} }
g_free(info);
} }