Blame SOURCES/0003-tabrmd-init.c-fix-leaks-on-main-to-thread-tpm2-insta.patch

d9c268
From 62ae28635ada2a74b526244e8ea69cef74c6c022 Mon Sep 17 00:00:00 2001
d9c268
From: William Roberts <william.c.roberts@intel.com>
d9c268
Date: Wed, 13 Jan 2021 13:52:06 -0600
d9c268
Subject: [PATCH 3/6] tabrmd-init.c: fix leaks on main to thread tpm2 instance
d9c268
d9c268
Theirs a case where the Tpm2 object coming in from main to the thread
d9c268
fails setup and the cleanup function doesn't unref it. Move it to the
d9c268
main cleanup routine and use g_clear_object to be *clear* on whom owns
d9c268
the reference.
d9c268
d9c268
Fixes leaks like:
d9c268
Indirect leak of 4176 byte(s) in 1 object(s) allocated from:
d9c268
    #0 0x7f652e71cdc6 in calloc (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10ddc6)
d9c268
    #1 0x7f652e25ad30 in g_malloc0 (/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x57d30)
d9c268
    #2 0x555ebb1a1c5f in sapi_context_init src/tpm2.c:162
d9c268
    #3 0x555ebb1a2fa8 in tpm2_new src/tpm2.c:438
d9c268
    #4 0x555ebb19d665 in init_thread_func src/tabrmd-init.c:178
d9c268
    #5 0x555ebb19bede in init_thread_func_tpm2_init_fail test/tabrmd-init_unit.c:199
d9c268
    #6 0x7f652e6074e0  (/usr/lib/x86_64-linux-gnu/libcmocka.so.0+0x54e0)
d9c268
d9c268
Signed-off-by: William Roberts <william.c.roberts@intel.com>
d9c268
---
d9c268
 src/tabrmd-init.c | 5 ++++-
d9c268
 1 file changed, 4 insertions(+), 1 deletion(-)
d9c268
d9c268
diff --git a/src/tabrmd-init.c b/src/tabrmd-init.c
d9c268
index 58e0103..866c852 100644
d9c268
--- a/src/tabrmd-init.c
d9c268
+++ b/src/tabrmd-init.c
d9c268
@@ -99,6 +99,9 @@ gmain_data_cleanup (gmain_data_t *data)
d9c268
     if (data->loop != NULL) {
d9c268
         main_loop_quit (data->loop);
d9c268
     }
d9c268
+    if (data->tpm2) {
d9c268
+        g_clear_object (&data->tpm2);
d9c268
+    }
d9c268
 
d9c268
     tabrmd_options_free(&data->options);
d9c268
 }
d9c268
@@ -208,7 +211,7 @@ init_thread_func (gpointer user_data)
d9c268
     g_clear_object (&session_list);
d9c268
     data->response_sink = response_sink_new ();
d9c268
     g_object_unref (command_attrs);
d9c268
-    g_object_unref (data->tpm2);
d9c268
+    g_clear_object (&data->tpm2);
d9c268
     /*
d9c268
      * Wire up the TPM command processing pipeline. TPM command buffers
d9c268
      * flow from the CommandSource, to the Tab then finally back to the
d9c268
-- 
d9c268
2.34.3
d9c268