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

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