Skip to content

Commit 446d5f2

Browse files
code refactor
1 parent f6143cf commit 446d5f2

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
- name: Build
5454
run: |
5555
rm -rf build
56-
cmake -B build . -G Ninja -DCMAKE_BUILD_TYPE=Debug -DENABLE_TESTS=ON -DENABLE_ASAN=OFF -DBUILD_EXECUTABLE=OFF
56+
cmake -B build . -G Ninja -DCMAKE_BUILD_TYPE=Debug -DENABLE_TESTS=ON -DENABLE_ASAN=ON -DBUILD_EXECUTABLE=OFF
5757
cmake --build build
5858
cd build && ctest --output-on-failure --verbose
5959

include/bitchat/services/noise_service.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ class NoiseService
2424
{
2525
public:
2626
NoiseService();
27-
~NoiseService() = default;
27+
~NoiseService();
28+
29+
// Cleanup method
30+
void cleanup();
2831

2932
// Session management
3033
std::shared_ptr<NoiseSession> createSession(const std::string &peerID, NoiseRole role);

src/bitchat/services/noise_service.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include "bitchat/core/constants.h"
33
#include "bitchat/helpers/noise_helper.h"
44
#include "bitchat/noise/noise_session_default.h"
5+
#include <openssl/err.h>
6+
#include <openssl/evp.h>
57
#include <openssl/rand.h>
68
#include <spdlog/spdlog.h>
79

@@ -16,6 +18,24 @@ NoiseService::NoiseService()
1618
}
1719
}
1820

21+
NoiseService::~NoiseService()
22+
{
23+
cleanup();
24+
}
25+
26+
void NoiseService::cleanup()
27+
{
28+
std::lock_guard<std::mutex> lock(sessionsMutex);
29+
30+
// Clear all sessions
31+
sessions.clear();
32+
33+
// Clear OpenSSL
34+
ERR_clear_error();
35+
EVP_cleanup();
36+
ERR_free_strings();
37+
}
38+
1939
std::shared_ptr<NoiseSession> NoiseService::createSession(const std::string &peerID, NoiseRole role)
2040
{
2141
std::lock_guard<std::mutex> lock(sessionsMutex);

0 commit comments

Comments
 (0)