Skip to content

Commit

Permalink
softmmu: Fix dirtylimit memory leak
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
alloc.young authored and HuangSuiXiao committed Aug 29, 2023
1 parent f5fe7c1 commit 58b4def
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions softmmu/dirtylimit.c
Original file line number Diff line number Diff line change
Expand Up @@ -653,28 +653,26 @@ struct DirtyLimitInfoList *qmp_query_vcpu_dirty_limit(Error **errp)

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;

if (!dirtylimit_in_service()) {
monitor_printf(mon, "Dirty page limit not enabled!\n");
return;
}

info = qmp_query_vcpu_dirty_limit(&err);
head = qmp_query_vcpu_dirty_limit(&err);
if (err) {
hmp_handle_error(mon, err);
return;
}

head = info;
for (limit = head; limit != NULL; limit = limit->next) {
for (info = head; info != NULL; info = info->next) {
monitor_printf(mon, "vcpu[%"PRIi64"], limit rate %"PRIi64 " (MB/s),"
" current rate %"PRIi64 " (MB/s)\n",
limit->value->cpu_index,
limit->value->limit_rate,
limit->value->current_rate);
info->value->cpu_index,
info->value->limit_rate,
info->value->current_rate);
}

g_free(info);
}

0 comments on commit 58b4def

Please sign in to comment.