diff mbox series

[PULL,1/3] softmmu: Fix dirtylimit memory leak

Message ID ff118704fa5498c64a55d7a732fd42515fdc356c.1693322363.git.yong.huang@smartx.com
State New
Headers show
Series [PULL,1/3] softmmu: Fix dirtylimit memory leak | expand

Commit Message

Yong Huang Aug. 29, 2023, 3:29 p.m. UTC
From: "alloc.young" <alloc.young@outlook.com>

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>
---
 softmmu/dirtylimit.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

Comments

Michael Tokarev Aug. 30, 2023, 4:55 p.m. UTC | #1
29.08.2023 18:29, Hyman Huang wrote:
> From: "alloc.young" <alloc.young@outlook.com>
> 
> Fix memory leak in hmp_info_vcpu_dirty_limit,use g_autoptr
> to handle memory deallocation.

It does not feel like -stable-worthy, or am I wrong and it should be picked up
for -stable?

Thanks,

/mjt
Yong Huang Aug. 31, 2023, 1:01 a.m. UTC | #2
On Thu, Aug 31, 2023 at 12:55 AM Michael Tokarev <mjt@tls.msk.ru> wrote:

> 29.08.2023 18:29, Hyman Huang wrote:
> > From: "alloc.young" <alloc.young@outlook.com>
> >
> > Fix memory leak in hmp_info_vcpu_dirty_limit,use g_autoptr
> > to handle memory deallocation.
>
> It does not feel like -stable-worthy, or am I wrong and it should be
> picked up
> for -stable?


Since the leak occurs when using the hmp command instead of qmp, which
lowers the frequency, it is, in my opinion, somewhat tolerable for the
dirtylimit feature.
It is undoubtedly not -stable-worthy for the memory leak issue by itself,
which is regrettable. :( And the valgrind tool would be applied as much as
possible for my further work.

Thanks,

Yong


> Thanks,
>
> /mjt
>
diff mbox series

Patch

diff --git a/softmmu/dirtylimit.c b/softmmu/dirtylimit.c
index 3c275ee55b..e3ff53b8fc 100644
--- a/softmmu/dirtylimit.c
+++ b/softmmu/dirtylimit.c
@@ -653,7 +653,8 @@  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()) {
@@ -661,20 +662,17 @@  void hmp_info_vcpu_dirty_limit(Monitor *mon, const QDict *qdict)
         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);
 }