Skip to contentSkip to conversation

chardev/tcp: fix error message double free error

PATCH Superseded lichun 2 participants 3 messages Jun 21, 2020

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

lichun

author
#0 lore raw

PATCH 1/1 chardev/tcp: fix error message double free error

---
 chardev/char-socket.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
chardev/char-socket.c +4 -1
index afebeec5c3..3b6c1c5848 100644
@@ -1086,7 +1086,10 @@ static void qemu_chr_socket_connected(QIOTask *task, void *opaque)
     if (qio_task_propagate_error(task, &err)) {
         tcp_chr_change_state(s, TCP_CHARDEV_STATE_DISCONNECTED);
         check_report_connect_error(chr, err);
-        error_free(err);
+        /* If connect_err_reported is true, it means err is already freed */
+        if (!s->connect_err_reported) {
+            error_free(err);
+        }
         goto cleanup;
     }
 
Signature · 1 line
2.18.4
#1 lore raw

Hi

Quoted 11 lines · lichun
---
 chardev/char-socket.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
chardev/char-socket.c +0 -0
index afebeec5c3..3b6c1c5848 100644

chardev/char-socket.c static void qemu_chr_socket_connected(QIOTask *task, void *opaque) · line 1092

Quoted 8 lines
chardev/char-socket.c +4 -1
@@ -1086,7 +1086,10 @@ static void qemu_chr_socket_connected(QIOTask *task, void *opaque)
     if (qio_task_propagate_error(task, &err)) {
         tcp_chr_change_state(s, TCP_CHARDEV_STATE_DISCONNECTED);
         check_report_connect_error(chr, err);
-        error_free(err);
+        /* If connect_err_reported is true, it means err is already freed */
+        if (!s->connect_err_reported) {
+            error_free(err);
+        }

Good catch (did you find it with a static analysis tool?).

Instead of checking connect_err_reported here, I would rather let check_report_connect_error() handle error_free(). Can you update the patch?

thanks

Quoted 6 lines
chardev/char-socket.c +0 -1
         goto cleanup;
     }
 
--

2.18.4

#2 lore raw
Quoted 9 lines

Hi

Quoted 6 lines · lichun

---
  chardev/char-socket.c | 5 ++++-

  1 file changed, 4 insertions(+), 1 deletion(-)
Quoted 15 lines

chardev/char-socket.c static void qemu_chr_socket_connected(QIOTask *task, void *opaque) · line 1092

Quoted 13 lines
chardev/char-socket.c +4 -1
index afebeec5c3..3b6c1c5848 100644
@@ -1086,7 +1086,10 @@ static void qemu_chr_socket_connected(QIOTask *task, void *opaque)
       if (qio_task_propagate_error(task, &err)) {
           tcp_chr_change_state(s, TCP_CHARDEV_STATE_DISCONNECTED);
           check_report_connect_error(chr, err);
-        error_free(err);
+        /* If connect_err_reported is true, it means err is already freed */
+        if (!s->connect_err_reported) {
+            error_free(err);
+        }

Good catch (did you find it with a static analysis tool?).

Yeah, I find it with gdb.

Quoted 4 lines

Instead of checking connect_err_reported here, I would rather let check_report_connect_error() handle error_free(). Can you update the patch?

Of course, I will.

Quoted 10 lines

thanks

Quoted 6 lines
chardev/char-socket.c +0 -1
           goto cleanup;
       }
 
--

2.18.4