Skip to contentSkip to conversation

fix some error memleaks

PATCH Applied Pan Nengyuan 5 participants 22 messages Aug 31, 2020 – Oct 10, 2020 Block layer

lore
Share & tools
lore
#0 lore raw

v2 cover fix some error memleaks

This series fix some Error/GError memleaks.

V2:
1. remove two patches.(One has aleardy applied. The other has fixed.)
2. change patch 5/10 and 7/10.

Pan Nengyuan (10):
qga/channel-posix: Plug memory leak in ga_channel_write_all() 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

 block/file-posix.c         |  2 +-
 blockdev.c                 |  1 +
 contrib/elf2dmp/pdb.c      |  1 +
 contrib/elf2dmp/qemu_elf.c |  1 +
 migration/colo.c           |  5 ++++-
 qga/channel-posix.c        |  6 +++++-
 target/i386/cpu.c          |  1 +
 target/i386/sev.c          |  1 +
 ui/gtk-gl-area.c           | 11 +++++++++++
 ui/vnc-auth-sasl.c         |  1 +
 10 files changed, 27 insertions(+), 3 deletions(-)
Signature · 1 line
2.18.2
#1 lore raw

PATCH v2 1/10 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]>
---
- V2: no changes in v2

---
 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
#2 lore raw

PATCH v2 2/10 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]>
---
- v2: no changes in v2

---
 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
#3 lore raw

PATCH v2 3/10 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]>
---
- v2: no changes in v2

---
 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
#4 lore raw

PATCH v2 4/10 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]>
---
- v2: no changes in v2

---
 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
#6 lore raw

PATCH v2 5/10 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. This patch check the return value of 'gdk_window_create_gl_context' and 'gdk_gl_context_realize', then free err to fix it.

---
Cc: Gerd Hoffmann <[email protected]>
---
V2->V1: check the return value of 'gdk_window_create_gl_context' and 'gdk_gl_context_realize' instead of omitting it(Suggested by Li Qiang)

---
 ui/gtk-gl-area.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
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;
 }
 
Signature · 1 line
2.18.2
#7 lore raw

Re: [PATCH v2 05/10] ui/gtk-gl-area: Plug memleak in gd_gl_area_create_context()

Quoted 8 lines · Pan Nengyuan

Receiving error in local variable err, and forgot to free it. This patch check the return value of 'gdk_window_create_gl_context' and 'gdk_gl_context_realize', then free err to fix it.

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

Added to UI queue.

thanks,
Gerd

#8 lore raw

PATCH v2 6/10 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]>
---
- V2: no changes in v2.

---
 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 v2 6/10
#9 lore raw

Re: [PATCH v2 06/10] target/i386/cpu: Fix memleak in x86_cpu_class_check_missing_features

target/i386/cpu.c static void x86_cpu_class_check_missing_features(X86CPUClass *xcc,

Quoted 21 lines · 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]>
---
- V2: no changes in v2.

---
 target/i386/cpu.c | 1 +
 1 file changed, 1 insertion(+)
target/i386/cpu.c +0 -0
index 588f32e136..4678aac0b4 100644
@@ -4872,6 +4872,7 @@ static void x86_cpu_class_check_missing_features(X86CPUClass *xcc,
       x86_cpu_expand_features(xc, &err);
       if (err) {
           /* Errors at x86_cpu_expand_features should never happen,
            * but in case it does, just report the model as not
            * runnable at all using the "type" property.
            */
           strList *new = g_new0(strList, 1);

target/i386/cpu.c static void x86_cpu_class_check_missing_features(X86CPUClass *xcc, · line 4878

Quoted 7 lines
target/i386/cpu.c +1 -0
         new->value = g_strdup("type");
         *next = new;
         next = &new->next;
+        error_free(err);
     }
 
     x86_cpu_filter_features(xc, false);

Recommended cleanup: change x86_cpu_filter_features() to return true on success, false on failure, then pass NULL here and check the return value. Can be done on top.

#10 lore raw

Re: [PATCH v2 06/10] target/i386/cpu: Fix memleak in x86_cpu_class_check_missing_features

Quoted 36 lines · Markus Armbruster

target/i386/cpu.c static void x86_cpu_class_check_missing_features(X86CPUClass *xcc,

Quoted 21 lines · 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]>
---
- V2: no changes in v2.

---
 target/i386/cpu.c | 1 +
 1 file changed, 1 insertion(+)
target/i386/cpu.c +0 -0
index 588f32e136..4678aac0b4 100644
@@ -4872,6 +4872,7 @@ static void x86_cpu_class_check_missing_features(X86CPUClass *xcc,
       x86_cpu_expand_features(xc, &err);
       if (err) {
           /* Errors at x86_cpu_expand_features should never happen,
            * but in case it does, just report the model as not
            * runnable at all using the "type" property.
            */
           strList *new = g_new0(strList, 1);
Quoted 6 lines
target/i386/cpu.c +1 -0
         new->value = g_strdup("type");
         *next = new;
         next = &new->next;
+        error_free(err);
     }
 
Quoted 8 lines

target/i386/cpu.c static void x86_cpu_class_check_missing_features(X86CPUClass *xcc, · line 4878

Quoted 1 line
target/i386/cpu.c +0 -0
     x86_cpu_filter_features(xc, false);

Recommended cleanup: change x86_cpu_filter_features() to return true on success, false on failure, then pass NULL here and check the return value. Can be done on top.

Agree with you, 'err' is not used, we can pass NULL here.
BTW, I think the func you mentioned shoule be x86_cpu_expand_features(), not x86_cpu_filter_features()?

Thanks.

Quoted 2 lines

.

#12 lore raw

PATCH v2 7/10 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]>
---
- V2: Arrange all 'error_report_err' in 'out' label(suggested by Li Qiang).

---
 migration/colo.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
migration/colo.c +4 -1
index ea7d1e9d4e..2288188fe2 100644
@@ -888,7 +888,6 @@ void *colo_process_incoming_thread(void *opaque)
     while (mis->state == MIGRATION_STATUS_COLO) {
         colo_wait_handle_message(mis, fb, bioc, &local_err);
         if (local_err) {
-            error_report_err(local_err);
             break;
         }
 
@@ -924,6 +923,10 @@ out:
         qemu_fclose(fb);
     }
 
+    if (local_err) {
+        error_report_err(local_err);
+    }
+
     /* Hope this not to be too long to loop here */
     qemu_sem_wait(&mis->colo_incoming_sem);
     qemu_sem_destroy(&mis->colo_incoming_sem);
Signature · 1 line
2.18.2
Reviewed-by on v2 7/10
#13 lore raw

Re: [PATCH v2 07/10] migration/colo: Plug memleaks in colo_process_incoming_thread

Quoted 6 lines · Pan Nengyuan <[email protected]> 于2020年8月31日周一 下午3:17写道:

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

Quoted 37 lines

---
Cc: Hailiang Zhang <[email protected]>
Cc: Juan Quintela <[email protected]>
Cc: "Dr. David Alan Gilbert" <[email protected]>
---
- V2: Arrange all 'error_report_err' in 'out' label(suggested by Li Qiang).

---
 migration/colo.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
migration/colo.c +4 -2
index ea7d1e9d4e..2288188fe2 100644
@@ -888,7 +888,6 @@ void *colo_process_incoming_thread(void *opaque)
     while (mis->state == MIGRATION_STATUS_COLO) {
         colo_wait_handle_message(mis, fb, bioc, &local_err);
         if (local_err) {
-            error_report_err(local_err);
             break;
         }
 
@@ -924,6 +923,10 @@ out:
         qemu_fclose(fb);
     }
 
+    if (local_err) {
+        error_report_err(local_err);
+    }
+
     /* Hope this not to be too long to loop here */
     qemu_sem_wait(&mis->colo_incoming_sem);
     qemu_sem_destroy(&mis->colo_incoming_sem);
--

2.18.2

#14 lore raw

PATCH v2 8/10 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]
---
- V2: no changes in v2.

---
 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
#15 lore raw

PATCH v2 9/10 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]
---
- V2: no changes in v2.

---
 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 v2 9/10
#16 lore raw

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

Quoted 8 lines · Pan Nengyuan <[email protected]> 于2020年8月31日周一 下午3:21写道:

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 28 lines

---
Cc: Kevin Wolf <[email protected]>
Cc: Max Reitz <[email protected]>
Cc: Aarushi Mehta <[email protected]>
Cc: [email protected]
---
- V2: no changes in v2.

---
 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

#17 lore raw

PATCH v2 10/10 vnc-auth-sasl: Plug memleak in vnc_socket_ip_addr_string

In reply to Pan Nengyuan

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

---
Cc: Gerd Hoffmann <[email protected]>
---
- V2: no changes in v2.

---
 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
#19 lore raw
In reply to Pan Nengyuan

ping!

Anyone queued the rest(patch 01/02/03/07/08/09)?

Quoted 30 lines · Pan Nengyuan

This series fix some Error/GError memleaks.

V2:
1. remove two patches.(One has aleardy applied. The other has fixed.)
2. change patch 5/10 and 7/10.

Pan Nengyuan (10):
qga/channel-posix: Plug memory leak in ga_channel_write_all() 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

 block/file-posix.c         |  2 +-
 blockdev.c                 |  1 +
 contrib/elf2dmp/pdb.c      |  1 +
 contrib/elf2dmp/qemu_elf.c |  1 +
 migration/colo.c           |  5 ++++-
 qga/channel-posix.c        |  6 +++++-
 target/i386/cpu.c          |  1 +
 target/i386/sev.c          |  1 +
 ui/gtk-gl-area.c           | 11 +++++++++++
 ui/vnc-auth-sasl.c         |  1 +
 10 files changed, 27 insertions(+), 3 deletions(-)
#20 lore raw

ping!

and cc: [email protected]

Quoted 35 lines · Pan Nengyuan

ping!

Anyone queued the rest(patch 01/02/03/07/08/09)?

Quoted 30 lines · Pan Nengyuan

This series fix some Error/GError memleaks.

V2:
1. remove two patches.(One has aleardy applied. The other has fixed.)
2. change patch 5/10 and 7/10.

Pan Nengyuan (10):
qga/channel-posix: Plug memory leak in ga_channel_write_all() 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

 block/file-posix.c         |  2 +-
 blockdev.c                 |  1 +
 contrib/elf2dmp/pdb.c      |  1 +
 contrib/elf2dmp/qemu_elf.c |  1 +
 migration/colo.c           |  5 ++++-
 qga/channel-posix.c        |  6 +++++-
 target/i386/cpu.c          |  1 +
 target/i386/sev.c          |  1 +
 ui/gtk-gl-area.c           | 11 +++++++++++
 ui/vnc-auth-sasl.c         |  1 +
 10 files changed, 27 insertions(+), 3 deletions(-)
#21 lore raw

ping!

Hello,

Some patches have been reviewed a few weeks ago but missed to queue.

The rest patches are the following:
https://patchwork.kernel.org/patch/11745621/
https://patchwork.kernel.org/patch/11745633/
https://patchwork.kernel.org/patch/11745629/
https://patchwork.kernel.org/patch/11745625/
https://patchwork.kernel.org/patch/11745627/
https://patchwork.kernel.org/patch/11745635/

Quoted 40 lines · Pan Nengyuan

ping!

and cc: [email protected]

Quoted 35 lines · Pan Nengyuan

ping!

Anyone queued the rest(patch 01/02/03/07/08/09)?

Quoted 30 lines · Pan Nengyuan

This series fix some Error/GError memleaks.

V2:
1. remove two patches.(One has aleardy applied. The other has fixed.)
2. change patch 5/10 and 7/10.

Pan Nengyuan (10):
qga/channel-posix: Plug memory leak in ga_channel_write_all() 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

 block/file-posix.c         |  2 +-
 blockdev.c                 |  1 +
 contrib/elf2dmp/pdb.c      |  1 +
 contrib/elf2dmp/qemu_elf.c |  1 +
 migration/colo.c           |  5 ++++-
 qga/channel-posix.c        |  6 +++++-
 target/i386/cpu.c          |  1 +
 target/i386/sev.c          |  1 +
 ui/gtk-gl-area.c           | 11 +++++++++++
 ui/vnc-auth-sasl.c         |  1 +
 10 files changed, 27 insertions(+), 3 deletions(-)