Skip to contentSkip to conversation

fix some error memleaks

PATCH Applied Pan Nengyuan 7 participants 39 messages Aug 14, 2020 – Aug 27, 2020 Block layer

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover fix some error memleaks

This series fix some Error/GError memleaks.

Pan Nengyuan (12):
qga/channel-posix: Plug memory leak in ga_channel_write_all() hw/vfio/ap: Plug memleak in vfio_ap_get_group() elf2dmp/qemu_elf: Plug memleak in QEMU_Elf_init elf2dmp/pdb: Plug memleak in pdb_init_from_file target/i386/sev: Plug memleak in sev_read_file_base64 ui/gtk-gl-area: Plug memleak in gd_gl_area_create_context() target/i386/cpu: Fix memleak in x86_cpu_class_check_missing_features migration/colo: Plug memleaks in colo_process_incoming_thread
blockdev: Fix a memleak in drive_backup_prepare() block/file-posix: fix a possible undefined behavior
vnc-auth-sasl: Plug memleak in vnc_socket_ip_addr_string
test-util-sockets: Fix a memleak in test_socket_unix_abstract_good

 block/file-posix.c         | 2 +-
 blockdev.c                 | 1 +
 contrib/elf2dmp/pdb.c      | 1 +
 contrib/elf2dmp/qemu_elf.c | 1 +
 hw/vfio/ap.c               | 1 +
 migration/colo.c           | 2 ++
 qga/channel-posix.c        | 6 +++++-
 target/i386/cpu.c          | 1 +
 target/i386/sev.c          | 1 +
 tests/test-util-sockets.c  | 1 +
 ui/gtk-gl-area.c           | 5 ++---
 ui/vnc-auth-sasl.c         | 1 +
 12 files changed, 18 insertions(+), 5 deletions(-)
Signature · 1 line
2.18.2
#1 lore raw

PATCH 1/12 qga/channel-posix: Plug memory leak in ga_channel_write_all()

Missing g_error_free on error path in ga_channel_write_all(). Fix that.

---
Cc: Michael Roth <[email protected]>

---
 qga/channel-posix.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
qga/channel-posix.c +5 -1
index 8fc205ad21..0b151cb87b 100644
@@ -249,7 +249,7 @@ GIOStatus ga_channel_write_all(GAChannel *c, const gchar *buf, gsize size)
             buf += written;
         } else if (status != G_IO_STATUS_AGAIN) {
             g_warning("error writing to channel: %s", err->message);
-            return status;
+            goto out;
         }
     }
 
@@ -261,6 +261,10 @@ GIOStatus ga_channel_write_all(GAChannel *c, const gchar *buf, gsize size)
         g_warning("error flushing channel: %s", err->message);
     }
 
+out:
+    if (err) {
+        g_error_free(err);
+    }
     return status;
 }
 
Signature · 1 line
2.18.2
Reviewed-by on v1 1/12
#2 lore raw

Re: [PATCH 01/12] qga/channel-posix: Plug memory leak in ga_channel_write_all()

Quoted 5 lines · Pan Nengyuan <[email protected]> 于2020年8月14日周五 下午6:30写道:

Missing g_error_free on error path in ga_channel_write_all(). Fix that.

Quoted 34 lines

---
Cc: Michael Roth <[email protected]>

---
 qga/channel-posix.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
qga/channel-posix.c +5 -2
index 8fc205ad21..0b151cb87b 100644
@@ -249,7 +249,7 @@ GIOStatus ga_channel_write_all(GAChannel *c, const gchar *buf, gsize size)
             buf += written;
         } else if (status != G_IO_STATUS_AGAIN) {
             g_warning("error writing to channel: %s", err->message);
-            return status;
+            goto out;
         }
     }
 
@@ -261,6 +261,10 @@ GIOStatus ga_channel_write_all(GAChannel *c, const gchar *buf, gsize size)
         g_warning("error flushing channel: %s", err->message);
     }
 
+out:
+    if (err) {
+        g_error_free(err);
+    }
     return status;
 }
 
--

2.18.2

#3 lore raw

PATCH 2/12 hw/vfio/ap: Plug memleak in vfio_ap_get_group()

In reply to Pan Nengyuan

Missing g_error_free() in vfio_ap_get_group() error path. Fix that.

---
Cc: Cornelia Huck <[email protected]>
Cc: Thomas Huth <[email protected]>
Cc: Christian Borntraeger <[email protected]>
Cc: Tony Krowiak <[email protected]>
Cc: Halil Pasic <[email protected]>
Cc: Pierre Morel <[email protected]>
Cc: Alex Williamson <[email protected]>
Cc: [email protected]

---
 hw/vfio/ap.c | 1 +
 1 file changed, 1 insertion(+)
hw/vfio/ap.c +1 -0
index b9330a8e6f..cec6fe1599 100644
@@ -71,6 +71,7 @@ static VFIOGroup *vfio_ap_get_group(VFIOAPDevice *vapdev, Error **errp)
     if (!group_path) {
         error_setg(errp, "%s: no iommu_group found for %s: %s",
                    VFIO_AP_DEVICE_TYPE, vapdev->vdev.sysfsdev, gerror->message);
+        g_error_free(gerror);
         return NULL;
     }
 
Signature · 1 line
2.18.2
Reviewed-by on v1 2/12
#4 lore raw

Re: [PATCH 02/12] hw/vfio/ap: Plug memleak in vfio_ap_get_group()

Quoted 23 lines · Pan Nengyuan

Missing g_error_free() in vfio_ap_get_group() error path. Fix that.

---
Cc: Cornelia Huck <[email protected]>
Cc: Thomas Huth <[email protected]>
Cc: Christian Borntraeger <[email protected]>
Cc: Tony Krowiak <[email protected]>
Cc: Halil Pasic <[email protected]>
Cc: Pierre Morel <[email protected]>
Cc: Alex Williamson <[email protected]>
Cc: [email protected]

---
  hw/vfio/ap.c | 1 +
  1 file changed, 1 insertion(+)
hw/vfio/ap.c +0 -0
index b9330a8e6f..cec6fe1599 100644

hw/vfio/ap.c static VFIOGroup *vfio_ap_get_group(VFIOAPDevice *vapdev, Error **errp) · line 77

Quoted 7 lines
hw/vfio/ap.c +1 -0
@@ -71,6 +71,7 @@ static VFIOGroup *vfio_ap_get_group(VFIOAPDevice *vapdev, Error **errp)
      if (!group_path) {
          error_setg(errp, "%s: no iommu_group found for %s: %s",
                     VFIO_AP_DEVICE_TYPE, vapdev->vdev.sysfsdev, gerror->message);
+        g_error_free(gerror);
          return NULL;
      }
 

Thanks Pan,

Signature · 2 lines
Pierre Morel
IBM Lab Boeblingen
#5 lore raw

Re: [PATCH 02/12] hw/vfio/ap: Plug memleak in vfio_ap_get_group()

In reply to Pan Nengyuan
Quoted 22 lines · On Fri, 14 Aug 2020 12:02:31 -0400 Pan Nengyuan <[email protected]> wrote:

Missing g_error_free() in vfio_ap_get_group() error path. Fix that.

---
Cc: Cornelia Huck <[email protected]>
Cc: Thomas Huth <[email protected]>
Cc: Christian Borntraeger <[email protected]>
Cc: Tony Krowiak <[email protected]>
Cc: Halil Pasic <[email protected]>
Cc: Pierre Morel <[email protected]>
Cc: Alex Williamson <[email protected]>
Cc: [email protected]

---
 hw/vfio/ap.c | 1 +
 1 file changed, 1 insertion(+)
hw/vfio/ap.c +0 -0
index b9330a8e6f..cec6fe1599 100644

hw/vfio/ap.c static VFIOGroup *vfio_ap_get_group(VFIOAPDevice *vapdev, Error **errp) · line 77

Quoted 7 lines
hw/vfio/ap.c +1 -0
@@ -71,6 +71,7 @@ static VFIOGroup *vfio_ap_get_group(VFIOAPDevice *vapdev, Error **errp)
     if (!group_path) {
         error_setg(errp, "%s: no iommu_group found for %s: %s",
                    VFIO_AP_DEVICE_TYPE, vapdev->vdev.sysfsdev, gerror->message);
+        g_error_free(gerror);
         return NULL;
     }
 

Thanks, applied.

Reviewed-by on v1 2/12
#6 lore raw

Re: [PATCH 02/12] hw/vfio/ap: Plug memleak in vfio_ap_get_group()

In reply to Pan Nengyuan
Quoted 5 lines · Pan Nengyuan <[email protected]> 于2020年8月14日周五 下午6:29写道:

Missing g_error_free() in vfio_ap_get_group() error path. Fix that.

I see Cornelia Huck has merged this in his tree.
Don't know whether this series will go separate maintainer's tree or as go only one maintainer's tree(maybe Paolo's misc tree?).

Thanks,
Li Qiang

Quoted 29 lines

---
Cc: Cornelia Huck <[email protected]>
Cc: Thomas Huth <[email protected]>
Cc: Christian Borntraeger <[email protected]>
Cc: Tony Krowiak <[email protected]>
Cc: Halil Pasic <[email protected]>
Cc: Pierre Morel <[email protected]>
Cc: Alex Williamson <[email protected]>
Cc: [email protected]

---
 hw/vfio/ap.c | 1 +
 1 file changed, 1 insertion(+)
hw/vfio/ap.c +1 -1
index b9330a8e6f..cec6fe1599 100644
@@ -71,6 +71,7 @@ static VFIOGroup *vfio_ap_get_group(VFIOAPDevice *vapdev, Error **errp)
     if (!group_path) {
         error_setg(errp, "%s: no iommu_group found for %s: %s",
                    VFIO_AP_DEVICE_TYPE, vapdev->vdev.sysfsdev, gerror->message);
+        g_error_free(gerror);
         return NULL;
     }
 
--

2.18.2

#7 lore raw

Re: [PATCH 02/12] hw/vfio/ap: Plug memleak in vfio_ap_get_group()

Quoted 10 lines · On Wed, 26 Aug 2020 19:03:37 +0800 Li Qiang <[email protected]> wrote:
Quoted 5 lines · Pan Nengyuan <[email protected]> 于2020年8月14日周五 下午6:29写道:

Missing g_error_free() in vfio_ap_get_group() error path. Fix that.

I see Cornelia Huck has merged this in his tree.

s/his/her/ :)

Quoted 2 lines

Don't know whether this series will go separate maintainer's tree or as go only one maintainer's tree(maybe Paolo's misc tree?).

Whatever works best, but I still plan to send a pull req this week to flush out my queue.

#8 lore raw

Re: [PATCH 02/12] hw/vfio/ap: Plug memleak in vfio_ap_get_group()

Quoted 8 lines · Cornelia Huck <[email protected]> 于2020年8月26日周三 下午7:41写道:
Quoted 4 lines · On Wed, 26 Aug 2020 19:03:37 +0800 Li Qiang <[email protected]> wrote:
Quoted 3 lines · Pan Nengyuan <[email protected]> 于2020年8月14日周五 下午6:29写道:

Missing g_error_free() in vfio_ap_get_group() error path. Fix that.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

I see Cornelia Huck has merged this in his tree.

s/his/her/ :)

I'm so sorry for this mistake.

Thanks,
Li Qiang

Quoted 10 lines
Quoted 3 lines

Don't know whether this series will go separate maintainer's tree or as go only one maintainer's tree(maybe Paolo's misc tree?).

Whatever works best, but I still plan to send a pull req this week to flush out my queue.

#9 lore raw

PATCH 3/12 elf2dmp/qemu_elf: Plug memleak in QEMU_Elf_init

In reply to Pan Nengyuan

Missing g_error_free in QEMU_Elf_init() error path. Fix that.

---
Cc: Viktor Prutyanov <[email protected]>

---
 contrib/elf2dmp/qemu_elf.c | 1 +
 1 file changed, 1 insertion(+)
contrib/elf2dmp/qemu_elf.c +1 -0
index 0db7816586..b601b6d7ba 100644
@@ -126,6 +126,7 @@ int QEMU_Elf_init(QEMU_Elf *qe, const char *filename)
     qe->gmf = g_mapped_file_new(filename, TRUE, &gerr);
     if (gerr) {
         eprintf("Failed to map ELF dump file \'%s\'\n", filename);
+        g_error_free(gerr);
         return 1;
     }
 
Signature · 1 line
2.18.2
Reviewed-by on v1 3/12
#10 lore raw

Re: [PATCH 03/12] elf2dmp/qemu_elf: Plug memleak in QEMU_Elf_init

Quoted 15 lines · On Fri, 14 Aug 2020 12:02:32 -0400 Pan Nengyuan <[email protected]> wrote:

Missing g_error_free in QEMU_Elf_init() error path. Fix that.

---
Cc: Viktor Prutyanov <[email protected]>

---
 contrib/elf2dmp/qemu_elf.c | 1 +
 1 file changed, 1 insertion(+)
contrib/elf2dmp/qemu_elf.c +0 -0
index 0db7816586..b601b6d7ba 100644

contrib/elf2dmp/qemu_elf.c int QEMU_Elf_init(QEMU_Elf *qe, const char · line 132

Quoted 7 lines
contrib/elf2dmp/qemu_elf.c +1 -0
@@ -126,6 +126,7 @@ int QEMU_Elf_init(QEMU_Elf *qe, const char
 *filename) qe->gmf = g_mapped_file_new(filename, TRUE, &gerr);
     if (gerr) {
         eprintf("Failed to map ELF dump file \'%s\'\n", filename);
+        g_error_free(gerr);
         return 1;
     }
 
Signature · 1 line
Viktor Prutyanov
Reviewed-by on v1 3/12
#11 lore raw

Re: [PATCH 03/12] elf2dmp/qemu_elf: Plug memleak in QEMU_Elf_init

In reply to Pan Nengyuan
Quoted 5 lines · Pan Nengyuan <[email protected]> 于2020年8月14日周五 下午6:28写道:

Missing g_error_free in QEMU_Elf_init() error path. Fix that.

Quoted 22 lines

---
Cc: Viktor Prutyanov <[email protected]>

---
 contrib/elf2dmp/qemu_elf.c | 1 +
 1 file changed, 1 insertion(+)
contrib/elf2dmp/qemu_elf.c +1 -1
index 0db7816586..b601b6d7ba 100644
@@ -126,6 +126,7 @@ int QEMU_Elf_init(QEMU_Elf *qe, const char *filename)
     qe->gmf = g_mapped_file_new(filename, TRUE, &gerr);
     if (gerr) {
         eprintf("Failed to map ELF dump file \'%s\'\n", filename);
+        g_error_free(gerr);
         return 1;
     }
 
--

2.18.2

#12 lore raw

PATCH 4/12 elf2dmp/pdb: Plug memleak in pdb_init_from_file

In reply to Pan Nengyuan

Missing g_error_free in pdb_init_from_file() error path. Fix that.

---
Cc: Viktor Prutyanov <[email protected]>

---
 contrib/elf2dmp/pdb.c | 1 +
 1 file changed, 1 insertion(+)
contrib/elf2dmp/pdb.c +1 -0
index a5bd40c99d..b3a6547068 100644
@@ -285,6 +285,7 @@ int pdb_init_from_file(const char *name, struct pdb_reader *reader)
     reader->gmf = g_mapped_file_new(name, TRUE, &gerr);
     if (gerr) {
         eprintf("Failed to map PDB file \'%s\'\n", name);
+        g_error_free(gerr);
         return 1;
     }
 
Signature · 1 line
2.18.2
Reviewed-by on v1 4/12
#13 lore raw

Re: [PATCH 04/12] elf2dmp/pdb: Plug memleak in pdb_init_from_file

Quoted 15 lines · On Fri, 14 Aug 2020 12:02:33 -0400 Pan Nengyuan <[email protected]> wrote:

Missing g_error_free in pdb_init_from_file() error path. Fix that.

---
Cc: Viktor Prutyanov <[email protected]>

---
 contrib/elf2dmp/pdb.c | 1 +
 1 file changed, 1 insertion(+)
contrib/elf2dmp/pdb.c +0 -0
index a5bd40c99d..b3a6547068 100644

contrib/elf2dmp/pdb.c int pdb_init_from_file(const char *name, struct · line 291

Quoted 7 lines
contrib/elf2dmp/pdb.c +1 -0
@@ -285,6 +285,7 @@ int pdb_init_from_file(const char *name, struct
 pdb_reader *reader) reader->gmf = g_mapped_file_new(name, TRUE,
 &gerr); if (gerr) {
         eprintf("Failed to map PDB file \'%s\'\n", name);
+        g_error_free(gerr);
         return 1;
     }
 
Signature · 1 line
Viktor Prutyanov
Reviewed-by on v1 4/12
#14 lore raw

Re: [PATCH 04/12] elf2dmp/pdb: Plug memleak in pdb_init_from_file

In reply to Pan Nengyuan
Quoted 5 lines · Pan Nengyuan <[email protected]> 于2020年8月14日周五 下午6:51写道:

Missing g_error_free in pdb_init_from_file() error path. Fix that.

Quoted 22 lines

---
Cc: Viktor Prutyanov <[email protected]>

---
 contrib/elf2dmp/pdb.c | 1 +
 1 file changed, 1 insertion(+)
contrib/elf2dmp/pdb.c +1 -1
index a5bd40c99d..b3a6547068 100644
@@ -285,6 +285,7 @@ int pdb_init_from_file(const char *name, struct pdb_reader *reader)
     reader->gmf = g_mapped_file_new(name, TRUE, &gerr);
     if (gerr) {
         eprintf("Failed to map PDB file \'%s\'\n", name);
+        g_error_free(gerr);
         return 1;
     }
 
--

2.18.2

#15 lore raw

PATCH 5/12 target/i386/sev: Plug memleak in sev_read_file_base64

In reply to Pan Nengyuan

Missing g_error_free() in sev_read_file_base64() error path. Fix that.

---
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>

---
 target/i386/sev.c | 1 +
 1 file changed, 1 insertion(+)
target/i386/sev.c +1 -0
index c3ecf86704..de4818da6d 100644
@@ -500,6 +500,7 @@ sev_read_file_base64(const char *filename, guchar **data, gsize *len)
 
     if (!g_file_get_contents(filename, &base64, &sz, &error)) {
         error_report("failed to read '%s' (%s)", filename, error->message);
+        g_error_free(error);
         return -1;
     }
 
Signature · 1 line
2.18.2
Reviewed-by on v1 5/12
#16 lore raw

Re: [PATCH 05/12] target/i386/sev: Plug memleak in sev_read_file_base64

Quoted 6 lines · Pan Nengyuan <[email protected]> 于2020年8月14日周五 下午6:37写道:

Missing g_error_free() in sev_read_file_base64() error path. Fix that.

Quoted 24 lines

---
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>

---
 target/i386/sev.c | 1 +
 1 file changed, 1 insertion(+)
target/i386/sev.c +1 -1
index c3ecf86704..de4818da6d 100644
@@ -500,6 +500,7 @@ sev_read_file_base64(const char *filename, guchar **data, gsize *len)
 
     if (!g_file_get_contents(filename, &base64, &sz, &error)) {
         error_report("failed to read '%s' (%s)", filename, error->message);
+        g_error_free(error);
         return -1;
     }
 
--

2.18.2

#17 lore raw

PATCH 6/12 ui/gtk-gl-area: Plug memleak in gd_gl_area_create_context()

In reply to Pan Nengyuan

Receiving error in local variable err, and forgot to free it. Considering that there is no place to deal with it. Clean up.

---
Cc: Gerd Hoffmann <[email protected]>

---
 ui/gtk-gl-area.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
ui/gtk-gl-area.c +2 -3
index 85f9d14c51..c740a7eb14 100644
@@ -142,15 +142,14 @@ QEMUGLContext gd_gl_area_create_context(DisplayChangeListener *dcl,
     VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
     GdkWindow *window;
     GdkGLContext *ctx;
-    GError *err = NULL;
 
     gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area));
     window = gtk_widget_get_window(vc->gfx.drawing_area);
-    ctx = gdk_window_create_gl_context(window, &err);
+    ctx = gdk_window_create_gl_context(window, NULL);
     gdk_gl_context_set_required_version(ctx,
                                         params->major_ver,
                                         params->minor_ver);
-    gdk_gl_context_realize(ctx, &err);
+    gdk_gl_context_realize(ctx, NULL);
     return ctx;
 }
 
Signature · 1 line
2.18.2
#18 lore raw

Re: [PATCH 06/12] ui/gtk-gl-area: Plug memleak in gd_gl_area_create_context()

Quoted 23 lines · Pan Nengyuan <[email protected]> 于2020年8月14日周五 下午6:15写道:

Receiving error in local variable err, and forgot to free it. Considering that there is no place to deal with it. Clean up.

---
Cc: Gerd Hoffmann <[email protected]>

---
 ui/gtk-gl-area.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
ui/gtk-gl-area.c +0 -1
index 85f9d14c51..c740a7eb14 100644
@@ -142,15 +142,14 @@ QEMUGLContext gd_gl_area_create_context(DisplayChangeListener *dcl,
     VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
     GdkWindow *window;
     GdkGLContext *ctx;
-    GError *err = NULL;
 
     gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area));

ui/gtk-gl-area.c QEMUGLContext gd_gl_area_create_context(DisplayChangeListener *dcl, · line 154

Quoted 10 lines
ui/gtk-gl-area.c +2 -2
     window = gtk_widget_get_window(vc->gfx.drawing_area);
-    ctx = gdk_window_create_gl_context(window, &err);
+    ctx = gdk_window_create_gl_context(window, NULL);
     gdk_gl_context_set_required_version(ctx,
                                         params->major_ver,
                                         params->minor_ver);
-    gdk_gl_context_realize(ctx, &err);
+    gdk_gl_context_realize(ctx, NULL);
     return ctx;
 }

Maybe we should check the return value of 'gdk_window_create_gl_context' and 'gdk_gl_context_realize' instead of omitting it?

Thanks,
Li Qiang

Quoted 6 lines
ui/gtk-gl-area.c +0 -1
--

2.18.2

#19 lore raw

Re: [PATCH 06/12] ui/gtk-gl-area: Plug memleak in gd_gl_area_create_context()

Quoted 23 lines · Li Qiang
Quoted 22 lines · Pan Nengyuan <[email protected]> 于2020年8月14日周五 下午6:15写道:

Receiving error in local variable err, and forgot to free it. Considering that there is no place to deal with it. Clean up.

---
Cc: Gerd Hoffmann <[email protected]>

---
 ui/gtk-gl-area.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
ui/gtk-gl-area.c +0 -1
index 85f9d14c51..c740a7eb14 100644
@@ -142,15 +142,14 @@ QEMUGLContext gd_gl_area_create_context(DisplayChangeListener *dcl,
     VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
     GdkWindow *window;
     GdkGLContext *ctx;
-    GError *err = NULL;
 
Quoted 14 lines

ui/gtk-gl-area.c QEMUGLContext gd_gl_area_create_context(DisplayChangeListener *dcl, · line 154

Quoted 11 lines
ui/gtk-gl-area.c +2 -2
     gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area));
     window = gtk_widget_get_window(vc->gfx.drawing_area);
-    ctx = gdk_window_create_gl_context(window, &err);
+    ctx = gdk_window_create_gl_context(window, NULL);
     gdk_gl_context_set_required_version(ctx,
                                         params->major_ver,
                                         params->minor_ver);
-    gdk_gl_context_realize(ctx, &err);
+    gdk_gl_context_realize(ctx, NULL);
     return ctx;
 }

Maybe we should check the return value of 'gdk_window_create_gl_context' and 'gdk_gl_context_realize' instead of omitting it?

OK, Agree with you.

How about check the value like the below?
(Return NULL when error happens in gdk_gl_context_realize. It's different from the original.)

Thanks.

--------

ui/gtk-gl-area.c +11 -0
index 85f9d14c51..98c22d23f5 100644
@@ -147,10 +147,21 @@ QEMUGLContext gd_gl_area_create_context(DisplayChangeListener *dcl,
     gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area));
     window = gtk_widget_get_window(vc->gfx.drawing_area);
     ctx = gdk_window_create_gl_context(window, &err);
+    if (err) {
+        g_printerr("Create gdk gl context failed: %s\n", err->message);
+        g_error_free(err);
+        return NULL;
+    }
     gdk_gl_context_set_required_version(ctx,
                                         params->major_ver,
                                         params->minor_ver);
     gdk_gl_context_realize(ctx, &err);
+    if (err) {
+        g_printerr("Realize gdk gl context failed: %s\n", err->message);
+        g_error_free(err);
+        g_clear_object(&ctx);
+        return NULL;
+    }
     return ctx;
 }
 
Quoted 12 lines

Thanks,
Li Qiang

Quoted 6 lines
ui/gtk-gl-area.c +0 -1
--

2.18.2

.

#20 lore raw

Re: [PATCH 06/12] ui/gtk-gl-area: Plug memleak in gd_gl_area_create_context()

Quoted 42 lines · Pan Nengyuan <[email protected]> 于2020年8月27日周四 下午3:06写道:
Quoted 23 lines · Li Qiang
Quoted 22 lines · Pan Nengyuan <[email protected]> 于2020年8月14日周五 下午6:15写道:

Receiving error in local variable err, and forgot to free it. Considering that there is no place to deal with it. Clean up.

---
Cc: Gerd Hoffmann <[email protected]>

---
 ui/gtk-gl-area.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
ui/gtk-gl-area.c +0 -1
index 85f9d14c51..c740a7eb14 100644
@@ -142,15 +142,14 @@ QEMUGLContext gd_gl_area_create_context(DisplayChangeListener *dcl,
     VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
     GdkWindow *window;
     GdkGLContext *ctx;
-    GError *err = NULL;
 
Quoted 14 lines

ui/gtk-gl-area.c QEMUGLContext gd_gl_area_create_context(DisplayChangeListener *dcl, · line 166

Quoted 11 lines
ui/gtk-gl-area.c +2 -2
     gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area));
     window = gtk_widget_get_window(vc->gfx.drawing_area);
-    ctx = gdk_window_create_gl_context(window, &err);
+    ctx = gdk_window_create_gl_context(window, NULL);
     gdk_gl_context_set_required_version(ctx,
                                         params->major_ver,
                                         params->minor_ver);
-    gdk_gl_context_realize(ctx, &err);
+    gdk_gl_context_realize(ctx, NULL);
     return ctx;
 }

Maybe we should check the return value of 'gdk_window_create_gl_context' and 'gdk_gl_context_realize' instead of omitting it?

Quoted 3 lines

OK, Agree with you.

How about check the value like the below?

I think it is OK.

Quoted 1 line

(Return NULL when error happens in gdk_gl_context_realize. It's different from the original.)

Don't familiar with the internal of how gtk-gl work.

Maybe you can wait for other review or Gerd's decision.

Thanks,
Li Qiang

Quoted 44 lines

Thanks.

--------

ui/gtk-gl-area.c +11 -0
index 85f9d14c51..98c22d23f5 100644
@@ -147,10 +147,21 @@ QEMUGLContext gd_gl_area_create_context(DisplayChangeListener *dcl,
     gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area));
     window = gtk_widget_get_window(vc->gfx.drawing_area);
     ctx = gdk_window_create_gl_context(window, &err);
+    if (err) {
+        g_printerr("Create gdk gl context failed: %s\n", err->message);
+        g_error_free(err);
+        return NULL;
+    }
     gdk_gl_context_set_required_version(ctx,
                                         params->major_ver,
                                         params->minor_ver);
     gdk_gl_context_realize(ctx, &err);
+    if (err) {
+        g_printerr("Realize gdk gl context failed: %s\n", err->message);
+        g_error_free(err);
+        g_clear_object(&ctx);
+        return NULL;
+    }
     return ctx;
 }
 
Quoted 13 lines

Thanks,
Li Qiang

Quoted 6 lines
ui/gtk-gl-area.c +0 -1
--

2.18.2

.

#21 lore raw

PATCH 7/12 target/i386/cpu: Fix memleak in x86_cpu_class_check_missing_features

In reply to Pan Nengyuan

'err' forgot to free in x86_cpu_class_check_missing_features error path. Fix that.

---
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>

---
 target/i386/cpu.c | 1 +
 1 file changed, 1 insertion(+)
target/i386/cpu.c +1 -0
index 588f32e136..4678aac0b4 100644
@@ -4872,6 +4872,7 @@ static void x86_cpu_class_check_missing_features(X86CPUClass *xcc,
         new->value = g_strdup("type");
         *next = new;
         next = &new->next;
+        error_free(err);
     }
 
     x86_cpu_filter_features(xc, false);
Signature · 1 line
2.18.2
Reviewed-by on v1 7/12
#22 lore raw

Re: [PATCH 07/12] target/i386/cpu: Fix memleak in x86_cpu_class_check_missing_features

Quoted 6 lines · Pan Nengyuan <[email protected]> 于2020年8月14日周五 下午6:38写道:

'err' forgot to free in x86_cpu_class_check_missing_features error path. Fix that.

Quoted 24 lines

---
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>

---
 target/i386/cpu.c | 1 +
 1 file changed, 1 insertion(+)
target/i386/cpu.c +1 -1
index 588f32e136..4678aac0b4 100644
@@ -4872,6 +4872,7 @@ static void x86_cpu_class_check_missing_features(X86CPUClass *xcc,
         new->value = g_strdup("type");
         *next = new;
         next = &new->next;
+        error_free(err);
     }
 
     x86_cpu_filter_features(xc, false);
--

2.18.2

#23 lore raw

PATCH 8/12 migration/colo: Plug memleaks in colo_process_incoming_thread

In reply to Pan Nengyuan

'local_err' forgot to free in colo_process_incoming_thread error path. Fix that.

---
Cc: Hailiang Zhang <[email protected]>
Cc: Juan Quintela <[email protected]>
Cc: "Dr. David Alan Gilbert" <[email protected]>

---
 migration/colo.c | 2 ++
 1 file changed, 2 insertions(+)
migration/colo.c +2 -0
index ea7d1e9d4e..17b5afc6b5 100644
@@ -870,6 +870,7 @@ void *colo_process_incoming_thread(void *opaque)
     replication_start_all(REPLICATION_MODE_SECONDARY, &local_err);
     if (local_err) {
         qemu_mutex_unlock_iothread();
+        error_report_err(local_err);
         goto out;
     }
 #else
@@ -882,6 +883,7 @@ void *colo_process_incoming_thread(void *opaque)
     colo_send_message(mis->to_src_file, COLO_MESSAGE_CHECKPOINT_READY,
                       &local_err);
     if (local_err) {
+        error_report_err(local_err);
         goto out;
     }
 
Signature · 1 line
2.18.2
#24 lore raw

Re: [PATCH 08/12] migration/colo: Plug memleaks in colo_process_incoming_thread

Quoted 27 lines · Pan Nengyuan <[email protected]> 于2020年8月14日周五 下午6:52写道:

'local_err' forgot to free in colo_process_incoming_thread error path. Fix that.

---
Cc: Hailiang Zhang <[email protected]>
Cc: Juan Quintela <[email protected]>
Cc: "Dr. David Alan Gilbert" <[email protected]>

---
 migration/colo.c | 2 ++
 1 file changed, 2 insertions(+)
migration/colo.c +1 -0
index ea7d1e9d4e..17b5afc6b5 100644
@@ -870,6 +870,7 @@ void *colo_process_incoming_thread(void *opaque)
     replication_start_all(REPLICATION_MODE_SECONDARY, &local_err);
     if (local_err) {
         qemu_mutex_unlock_iothread();
+        error_report_err(local_err);
         goto out;
     }
 #else

migration/colo.c void *colo_process_incoming_thread(void *opaque) · line 889

Quoted 7 lines
migration/colo.c +1 -0
@@ -882,6 +883,7 @@ void *colo_process_incoming_thread(void *opaque)
     colo_send_message(mis->to_src_file, COLO_MESSAGE_CHECKPOINT_READY,
                       &local_err);
     if (local_err) {
+        error_report_err(local_err);
         goto out;
     }
 

Could we arrange 'error_report_err' in 'out' label? Like this:

if (local_err) {
    error_report_err(local_err);
}

Thanks,
Li Qiang

Quoted 4 lines

--
2.18.2

#25 lore raw

Re: [PATCH 08/12] migration/colo: Plug memleaks in colo_process_incoming_thread

Quoted 39 lines · Li Qiang
Quoted 27 lines · Pan Nengyuan <[email protected]> 于2020年8月14日周五 下午6:52写道:

'local_err' forgot to free in colo_process_incoming_thread error path. Fix that.

---
Cc: Hailiang Zhang <[email protected]>
Cc: Juan Quintela <[email protected]>
Cc: "Dr. David Alan Gilbert" <[email protected]>

---
 migration/colo.c | 2 ++
 1 file changed, 2 insertions(+)
migration/colo.c +1 -0
index ea7d1e9d4e..17b5afc6b5 100644
@@ -870,6 +870,7 @@ void *colo_process_incoming_thread(void *opaque)
     replication_start_all(REPLICATION_MODE_SECONDARY, &local_err);
     if (local_err) {
         qemu_mutex_unlock_iothread();
+        error_report_err(local_err);
         goto out;
     }
 #else

migration/colo.c void *colo_process_incoming_thread(void *opaque) · line 889

Quoted 7 lines
migration/colo.c +1 -0
@@ -882,6 +883,7 @@ void *colo_process_incoming_thread(void *opaque)
     colo_send_message(mis->to_src_file, COLO_MESSAGE_CHECKPOINT_READY,
                       &local_err);
     if (local_err) {
+        error_report_err(local_err);
         goto out;
     }
 

Could we arrange 'error_report_err' in 'out' label? Like this:

Quoted 3 lines
if (local_err) {
    error_report_err(local_err);
}

Similar to the other place in the same function, I didn't arrange them in 'out' label:

    while (mis->state == MIGRATION_STATUS_COLO) {
        colo_wait_handle_message(mis, fb, bioc, &local_err);
        if (local_err) {
            error_report_err(local_err);
            break;
        }

But I think it's a good idea to arrange them in 'out' label. I will change it.

Thanks.

Quoted 12 lines

Thanks,
Li Qiang

Quoted 4 lines

--
2.18.2

.

#26 lore raw

PATCH 9/12 blockdev: Fix a memleak in drive_backup_prepare()

In reply to Pan Nengyuan

'local_err' seems forgot to propagate in error path, it'll cause a memleak. Fix it.

---
Cc: Kevin Wolf <[email protected]>
Cc: Max Reitz <[email protected]>
Cc: Markus Armbruster <[email protected]>
Cc: [email protected]

---
 blockdev.c | 1 +
 1 file changed, 1 insertion(+)
blockdev.c +1 -0
index 3848a9c8ab..842ac289c1 100644
@@ -1801,6 +1801,7 @@ static void drive_backup_prepare(BlkActionState *common, Error **errp)
     if (set_backing_hd) {
         bdrv_set_backing_hd(target_bs, source, &local_err);
         if (local_err) {
+            error_propagate(errp, local_err);
             goto unref;
         }
     }
Signature · 1 line
2.18.2
Reviewed-by on v1 9/12
#27 lore raw

Re: [PATCH 09/12] blockdev: Fix a memleak in drive_backup_prepare()

Am 14.08.2020 um 18:02 hat Pan Nengyuan geschrieben:

Quoted 5 lines

'local_err' seems forgot to propagate in error path, it'll cause a memleak. Fix it.

I wonder if using ERRP_GUARD() wouldn't simplify this. Anyway, the fix looks correct:

Reviewed-by on v1 9/12
#28 lore raw

Re: [PATCH 09/12] blockdev: Fix a memleak in drive_backup_prepare()

In reply to Pan Nengyuan
Quoted 6 lines · Pan Nengyuan <[email protected]> 于2020年8月14日周五 下午6:54写道:

'local_err' seems forgot to propagate in error path, it'll cause a memleak. Fix it.

Quoted 25 lines

---
Cc: Kevin Wolf <[email protected]>
Cc: Max Reitz <[email protected]>
Cc: Markus Armbruster <[email protected]>
Cc: [email protected]

---
 blockdev.c | 1 +
 1 file changed, 1 insertion(+)
blockdev.c +1 -1
index 3848a9c8ab..842ac289c1 100644
@@ -1801,6 +1801,7 @@ static void drive_backup_prepare(BlkActionState *common, Error **errp)
     if (set_backing_hd) {
         bdrv_set_backing_hd(target_bs, source, &local_err);
         if (local_err) {
+            error_propagate(errp, local_err);
             goto unref;
         }
     }
--

2.18.2

#29 lore raw

PATCH 10/12 block/file-posix: fix a possible undefined behavior

In reply to Pan Nengyuan

local_err is not initialized to NULL, it will cause a assert error as below:
qemu/util/error.c:59: error_setv: Assertion `*errp == NULL' failed.

---
Cc: Kevin Wolf <[email protected]>
Cc: Max Reitz <[email protected]>
Cc: Aarushi Mehta <[email protected]>
Cc: [email protected]

---
 block/file-posix.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/file-posix.c +1 -1
index 9a00d4190a..697a7d9eea 100644
@@ -2113,7 +2113,7 @@ static void raw_aio_attach_aio_context(BlockDriverState *bs,
 #endif
 #ifdef CONFIG_LINUX_IO_URING
     if (s->use_linux_io_uring) {
-        Error *local_err;
+        Error *local_err = NULL;
         if (!aio_setup_linux_io_uring(new_context, &local_err)) {
             error_reportf_err(local_err, "Unable to use linux io_uring, "
                                          "falling back to thread pool: ");
Signature · 1 line
2.18.2
Reviewed-by on v1 10/12
#30 lore raw

Re: [PATCH 10/12] block/file-posix: fix a possible undefined behavior

Quoted 6 lines · Pan Nengyuan

local_err is not initialized to NULL, it will cause a assert error as below:
qemu/util/error.c:59: error_setv: Assertion `*errp == NULL' failed.

Quoted 8 lines

---
Cc: Kevin Wolf <[email protected]>
Cc: Max Reitz <[email protected]>
Cc: Aarushi Mehta <[email protected]>
Cc: [email protected]

---
 block/file-posix.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Thanks,
Stefano

Quoted 18 lines
block/file-posix.c +1 -1
index 9a00d4190a..697a7d9eea 100644
@@ -2113,7 +2113,7 @@ static void raw_aio_attach_aio_context(BlockDriverState *bs,
 #endif
 #ifdef CONFIG_LINUX_IO_URING
     if (s->use_linux_io_uring) {
-        Error *local_err;
+        Error *local_err = NULL;
         if (!aio_setup_linux_io_uring(new_context, &local_err)) {
             error_reportf_err(local_err, "Unable to use linux io_uring, "
                                          "falling back to thread pool: ");
Signature · 1 line
2.18.2
Reviewed-by on v1 10/12
#31 lore raw

Re: [PATCH 10/12] block/file-posix: fix a possible undefined behavior

In reply to Pan Nengyuan

Am 14.08.2020 um 18:02 hat Pan Nengyuan geschrieben:

Quoted 6 lines

local_err is not initialized to NULL, it will cause a assert error as below:
qemu/util/error.c:59: error_setv: Assertion `*errp == NULL' failed.

Reviewed-by on v1 10/12
#32 lore raw

Re: [PATCH 10/12] block/file-posix: fix a possible undefined behavior

In reply to Pan Nengyuan
Quoted 7 lines · Pan Nengyuan <[email protected]> 于2020年8月14日周五 下午6:32写道:

local_err is not initialized to NULL, it will cause a assert error as below:
qemu/util/error.c:59: error_setv: Assertion `*errp == NULL' failed.

Quoted 26 lines

---
Cc: Kevin Wolf <[email protected]>
Cc: Max Reitz <[email protected]>
Cc: Aarushi Mehta <[email protected]>
Cc: [email protected]

---
 block/file-posix.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/file-posix.c +1 -2
index 9a00d4190a..697a7d9eea 100644
@@ -2113,7 +2113,7 @@ static void raw_aio_attach_aio_context(BlockDriverState *bs,
 #endif
 #ifdef CONFIG_LINUX_IO_URING
     if (s->use_linux_io_uring) {
-        Error *local_err;
+        Error *local_err = NULL;
         if (!aio_setup_linux_io_uring(new_context, &local_err)) {
             error_reportf_err(local_err, "Unable to use linux io_uring, "
                                          "falling back to thread pool: ");
--

2.18.2

#33 lore raw

PATCH 11/12 vnc-auth-sasl: Plug memleak in vnc_socket_ip_addr_string

In reply to Pan Nengyuan

'addr' forgot to free in vnc_socket_ip_addr_string error path. Fix that.

---
Cc: Gerd Hoffmann <[email protected]>

---
 ui/vnc-auth-sasl.c | 1 +
 1 file changed, 1 insertion(+)
ui/vnc-auth-sasl.c +1 -0
index 7b2b09f242..0517b2ead9 100644
@@ -522,6 +522,7 @@ vnc_socket_ip_addr_string(QIOChannelSocket *ioc,
 
     if (addr->type != SOCKET_ADDRESS_TYPE_INET) {
         error_setg(errp, "Not an inet socket type");
+        qapi_free_SocketAddress(addr);
         return NULL;
     }
     ret = g_strdup_printf("%s;%s", addr->u.inet.host, addr->u.inet.port);
Signature · 1 line
2.18.2
Reviewed-by on v1 11/12
#34 lore raw

Re: [PATCH 11/12] vnc-auth-sasl: Plug memleak in vnc_socket_ip_addr_string

Quoted 2 lines · Pan Nengyuan <[email protected]> 于2020年8月14日周五 下午6:40写道:

'addr' forgot to free in vnc_socket_ip_addr_string error path. Fix that.

s/forgot/is forgot, I think the maintainer will do this minor adjustment.

.

Quoted 3 lines
Quoted 22 lines

---
Cc: Gerd Hoffmann <[email protected]>

---
 ui/vnc-auth-sasl.c | 1 +
 1 file changed, 1 insertion(+)
ui/vnc-auth-sasl.c +1 -1
index 7b2b09f242..0517b2ead9 100644
@@ -522,6 +522,7 @@ vnc_socket_ip_addr_string(QIOChannelSocket *ioc,
 
     if (addr->type != SOCKET_ADDRESS_TYPE_INET) {
         error_setg(errp, "Not an inet socket type");
+        qapi_free_SocketAddress(addr);
         return NULL;
     }
     ret = g_strdup_printf("%s;%s", addr->u.inet.host, addr->u.inet.port);
--

2.18.2

#35 lore raw

PATCH 12/12 test-util-sockets: Fix a memleak in test_socket_unix_abstract_good

In reply to Pan Nengyuan

Fix a memleak in test_socket_unix_abstract_good().

---
 tests/test-util-sockets.c | 1 +
 1 file changed, 1 insertion(+)
tests/test-util-sockets.c +1 -0
index 261dc48c03..5c4204a130 100644
@@ -312,6 +312,7 @@ static void test_socket_unix_abstract_good(void)
     g_thread_join(cli);
     g_thread_join(serv);
 
+    g_rand_free(r);
     g_free(abstract_sock_name);
 }
 #endif
Signature · 1 line
2.18.2
#36 lore raw

Re: [PATCH 12/12] test-util-sockets: Fix a memleak in test_socket_unix_abstract_good

Quoted 6 lines · Pan Nengyuan <[email protected]> 于2020年8月14日周五 下午6:18写道:

Fix a memleak in test_socket_unix_abstract_good().

---

Hi Nengyuan,
I have sent this two month ago:
-->https://lists.gnu.org/archive/html/qemu-devel/2020-06/msg00809.html

seems the maintainer forget to push it to upstream.

Thanks,
Li Qiang

Quoted 19 lines
 tests/test-util-sockets.c | 1 +
 1 file changed, 1 insertion(+)
tests/test-util-sockets.c +1 -1
index 261dc48c03..5c4204a130 100644
@@ -312,6 +312,7 @@ static void test_socket_unix_abstract_good(void)
     g_thread_join(cli);
     g_thread_join(serv);
 
+    g_rand_free(r);
     g_free(abstract_sock_name);
 }
 #endif
--

2.18.2

#37 lore raw

Re: [PATCH 12/12] test-util-sockets: Fix a memleak in test_socket_unix_abstract_good

Quoted 8 lines · Li Qiang
Quoted 6 lines · Pan Nengyuan <[email protected]> 于2020年8月14日周五 下午6:18写道:

Fix a memleak in test_socket_unix_abstract_good().

---

Quoted 5 lines

Hi Nengyuan,
I have sent this two month ago:
-->https://lists.gnu.org/archive/html/qemu-devel/2020-06/msg00809.html

seems the maintainer forget to push it to upstream.

Yes, it's the same. Let's ignore this one.

Thanks.

Quoted 24 lines

Thanks,
Li Qiang

Quoted 19 lines
 tests/test-util-sockets.c | 1 +
 1 file changed, 1 insertion(+)
tests/test-util-sockets.c +1 -1
index 261dc48c03..5c4204a130 100644
@@ -312,6 +312,7 @@ static void test_socket_unix_abstract_good(void)
     g_thread_join(cli);
     g_thread_join(serv);
 
+    g_rand_free(r);
     g_free(abstract_sock_name);
 }
 #endif
--

2.18.2

#38 lore raw
In reply to Pan Nengyuan

ping!

Quoted 30 lines · Pan Nengyuan

This series fix some Error/GError memleaks.

Pan Nengyuan (12):
qga/channel-posix: Plug memory leak in ga_channel_write_all() hw/vfio/ap: Plug memleak in vfio_ap_get_group() elf2dmp/qemu_elf: Plug memleak in QEMU_Elf_init elf2dmp/pdb: Plug memleak in pdb_init_from_file target/i386/sev: Plug memleak in sev_read_file_base64 ui/gtk-gl-area: Plug memleak in gd_gl_area_create_context() target/i386/cpu: Fix memleak in x86_cpu_class_check_missing_features migration/colo: Plug memleaks in colo_process_incoming_thread
blockdev: Fix a memleak in drive_backup_prepare() block/file-posix: fix a possible undefined behavior
vnc-auth-sasl: Plug memleak in vnc_socket_ip_addr_string
test-util-sockets: Fix a memleak in test_socket_unix_abstract_good

 block/file-posix.c         | 2 +-
 blockdev.c                 | 1 +
 contrib/elf2dmp/pdb.c      | 1 +
 contrib/elf2dmp/qemu_elf.c | 1 +
 hw/vfio/ap.c               | 1 +
 migration/colo.c           | 2 ++
 qga/channel-posix.c        | 6 +++++-
 target/i386/cpu.c          | 1 +
 target/i386/sev.c          | 1 +
 tests/test-util-sockets.c  | 1 +
 ui/gtk-gl-area.c           | 5 ++---
 ui/vnc-auth-sasl.c         | 1 +
 12 files changed, 18 insertions(+), 5 deletions(-)