Blame SOURCES/0002-usbredirparser-reset-parser-s-fields-on-unserialize.patch

a4751a
From b93c4cae1aebda786a478677d6364308e4579ade Mon Sep 17 00:00:00 2001
a4751a
From: Victor Toso <victortoso@redhat.com>
a4751a
Date: Sat, 25 Jun 2022 00:29:12 +0200
a4751a
Subject: [PATCH 2/2] usbredirparser: reset parser's fields on unserialize
a4751a
Content-type: text/plain
a4751a
a4751a
This is a followup from previous commit and fixes the following leak.
a4751a
a4751a
 | 104 (24 direct, 80 indirect) bytes in 1 blocks are definitely lost in loss record 15 of 19
a4751a
 |    at 0x484A464: calloc (vg_replace_malloc.c:1328)
a4751a
 |    by 0x485A238: usbredirparser_queue (usbredirparser.c:1235)
a4751a
 |    by 0x485A571: usbredirparser_init (usbredirparser.c:227)
a4751a
 |    by 0x40130B: get_usbredirparser (serializer.c:77)
a4751a
 |    by 0x401379: simple (serializer.c:95)
a4751a
 |    by 0x48FA3DD: ??? (in /usr/lib64/libglib-2.0.so.0.7200.2)
a4751a
 |    by 0x48FA144: ??? (in /usr/lib64/libglib-2.0.so.0.7200.2)
a4751a
 |    by 0x48FA8E1: g_test_run_suite (in /usr/lib64/libglib-2.0.so.0.7200.2)
a4751a
 |    by 0x48FA94C: g_test_run (in /usr/lib64/libglib-2.0.so.0.7200.2)
a4751a
 |    by 0x401161: main (serializer.c:112)
a4751a
 |
a4751a
 | LEAK SUMMARY:
a4751a
 |    definitely lost: 24 bytes in 1 blocks
a4751a
 |    indirectly lost: 80 bytes in 1 blocks
a4751a
 |      possibly lost: 0 bytes in 0 blocks
a4751a
 |    still reachable: 25,500 bytes in 17 blocks
a4751a
 |         suppressed: 0 bytes in 0 blocks
a4751a
 | Reachable blocks (those to which a pointer was found) are not shown.
a4751a
 | To see them, rerun with: --leak-check=full --show-leak-kinds=all
a4751a
a4751a
Signed-off-by: Victor Toso <victortoso@redhat.com>
a4751a
---
a4751a
 usbredirparser/usbredirparser.c | 15 +++++++++++++++
a4751a
 1 file changed, 15 insertions(+)
a4751a
a4751a
diff --git a/usbredirparser/usbredirparser.c b/usbredirparser/usbredirparser.c
a4751a
index a5dd0e7..9bfc27c 100644
a4751a
--- a/usbredirparser/usbredirparser.c
a4751a
+++ b/usbredirparser/usbredirparser.c
a4751a
@@ -1823,6 +1823,21 @@ int usbredirparser_unserialize(struct usbredirparser *parser_pub,
a4751a
         return -1;
a4751a
     }
a4751a
 
a4751a
+    {
a4751a
+        /* We need to reset parser's state to receive unserialized
a4751a
+         * data. */
a4751a
+        struct usbredirparser_buf *wbuf = parser->write_buf;
a4751a
+        while (wbuf) {
a4751a
+            struct usbredirparser_buf *next_wbuf = wbuf->next;
a4751a
+            free(wbuf->buf);
a4751a
+            free(wbuf);
a4751a
+            wbuf = next_wbuf;
a4751a
+        }
a4751a
+        parser->write_buf = NULL;
a4751a
+        parser->write_buf_count = 0;
a4751a
+        parser->write_buf_total_size = 0;
a4751a
+    }
a4751a
+
a4751a
     if (unserialize_int(parser, &state, &remain, &i, "length")) {
a4751a
         usbredirparser_assert_invariants(parser);
a4751a
         return -1;
a4751a
-- 
a4751a
2.37.1
a4751a