From a3817775ce2ba5573750679cd04a24b58026960d Mon Sep 17 00:00:00 2001
From: "Constantin P." <papizh.konstantin@demlabs.net>
Date: Thu, 19 Sep 2024 17:37:05 +0700
Subject: [PATCH] Out-of-scope usage fix

---
 crypto/include/dap_hash.h   | 15 ++++++++-------
 crypto/src/dap_cert.c       |  7 ++-----
 net/client/dap_client_pvt.c |  4 +++-
 3 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/crypto/include/dap_hash.h b/crypto/include/dap_hash.h
index 7a194c8bd..ebd8b63e2 100755
--- a/crypto/include/dap_hash.h
+++ b/crypto/include/dap_hash.h
@@ -164,13 +164,14 @@ DAP_STATIC_INLINE char *dap_hash_fast_str_new( const void *a_data, size_t a_data
     return NULL;
 }
 
-#define dap_get_data_hash_str_static(data,data_size,strname) \
-do { \
-    strname = DAP_NEW_STACK_SIZE(char, DAP_CHAIN_HASH_FAST_STR_SIZE); \
-    dap_hash_fast_t dummy_hash; \
-    dap_hash_fast(data,data_size,&dummy_hash); \
-    dap_chain_hash_fast_to_str(&dummy_hash,strname,DAP_CHAIN_HASH_FAST_STR_SIZE); \
-} while (0)
+DAP_STATIC_INLINE dap_hash_str_t dap_get_data_hash_str(const void *a_data, size_t a_data_size)
+{
+    dap_hash_str_t l_ret = { };
+    dap_hash_fast_t dummy_hash;
+    dap_hash_fast(a_data, a_data_size, &dummy_hash);
+    dap_chain_hash_fast_to_str(&dummy_hash, l_ret.s, DAP_CHAIN_HASH_FAST_STR_SIZE);
+    return l_ret;
+}
 
 #ifdef __cplusplus
 }
diff --git a/crypto/src/dap_cert.c b/crypto/src/dap_cert.c
index 059b80139..f1f0d8693 100755
--- a/crypto/src/dap_cert.c
+++ b/crypto/src/dap_cert.c
@@ -236,11 +236,8 @@ dap_cert_t * dap_cert_generate_mem_with_seed(const char * a_cert_name, dap_enc_k
     if (l_enc_key) {
         dap_cert_t * l_cert = dap_cert_new(a_cert_name);
         l_cert->enc_key = l_enc_key;
-        if (a_seed && a_seed_size) {
-            char *l_hash_str;
-            dap_get_data_hash_str_static(a_seed, a_seed_size, l_hash_str);
-            log_it(L_DEBUG, "Certificate generated with seed hash %s", l_hash_str);
-        }
+        if (a_seed && a_seed_size)
+            log_it(L_DEBUG, "Certificate generated with seed hash %s", dap_get_data_hash_str(a_seed, a_seed_size).s);
         return l_cert;
     } else {
         log_it(L_ERROR,"Can't generate key in memory!");
diff --git a/net/client/dap_client_pvt.c b/net/client/dap_client_pvt.c
index 12df95cb8..7e7b88faa 100644
--- a/net/client/dap_client_pvt.c
+++ b/net/client/dap_client_pvt.c
@@ -144,7 +144,9 @@ static void s_client_internal_clean(dap_client_pvt_t *a_client_pvt)
     }
     if (a_client_pvt->stream_es) {
         dap_stream_delete_unsafe(a_client_pvt->stream);
-        a_client_pvt->stream = a_client_pvt->stream_es = a_client_pvt->stream_key = NULL;
+        a_client_pvt->stream = NULL;
+        a_client_pvt->stream_es = NULL;
+        a_client_pvt->stream_key = NULL;
         a_client_pvt->stream_id = 0;
     }
 
-- 
GitLab