From 7323c387769d22b53f11e3bf66833fa8e8d61833 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 9 Jan 2022 15:29:03 +0100 Subject: [PATCH] Make sha256's factory method return a ref<> instead of a raw pointer. --- backends/hash_hashlib/hlib_sha256.cpp | 2 +- backends/hash_hashlib/hlib_sha256.h | 2 +- core/hash/sha256.cpp | 4 ++-- core/hash/sha256.h | 4 ++-- core/http/session_manager.cpp | 4 +--- 5 files changed, 7 insertions(+), 9 deletions(-) diff --git a/backends/hash_hashlib/hlib_sha256.cpp b/backends/hash_hashlib/hlib_sha256.cpp index 52bf413..8b7503f 100644 --- a/backends/hash_hashlib/hlib_sha256.cpp +++ b/backends/hash_hashlib/hlib_sha256.cpp @@ -49,6 +49,6 @@ HashLibSHA256::HashLibSHA256() { HashLibSHA256::~HashLibSHA256() { } -SHA256 *HashLibSHA256::_creation_func() { +Ref HashLibSHA256::_creation_func() { return new HashLibSHA256(); } \ No newline at end of file diff --git a/backends/hash_hashlib/hlib_sha256.h b/backends/hash_hashlib/hlib_sha256.h index a1aafa4..c69d1d5 100644 --- a/backends/hash_hashlib/hlib_sha256.h +++ b/backends/hash_hashlib/hlib_sha256.h @@ -23,7 +23,7 @@ public: ~HashLibSHA256(); protected: - static SHA256 *_creation_func(); + static Ref _creation_func(); _SHA256 hasher; }; diff --git a/core/hash/sha256.cpp b/core/hash/sha256.cpp index 89b3f32..cf12511 100644 --- a/core/hash/sha256.cpp +++ b/core/hash/sha256.cpp @@ -8,7 +8,7 @@ SHA256::~SHA256() { } -SHA256 *SHA256::get() { +Ref SHA256::get() { if (_sha_256_creation_func == nullptr) { printf("Error: static SHA256 *get(): creation_func == nullptr\n"); return nullptr; @@ -17,4 +17,4 @@ SHA256 *SHA256::get() { return _sha_256_creation_func(); } -SHA256 *(*SHA256::_sha_256_creation_func)(void) = nullptr; +Ref (*SHA256::_sha_256_creation_func)(void) = nullptr; diff --git a/core/hash/sha256.h b/core/hash/sha256.h index c609817..22b994d 100644 --- a/core/hash/sha256.h +++ b/core/hash/sha256.h @@ -18,13 +18,13 @@ public: virtual void reset() = 0; - static SHA256 *get(); + static Ref get(); SHA256(); virtual ~SHA256(); protected: - static SHA256 *(*_sha_256_creation_func)(void); + static Ref (*_sha_256_creation_func)(void); }; #endif \ No newline at end of file diff --git a/core/http/session_manager.cpp b/core/http/session_manager.cpp index 31d3f92..968e400 100644 --- a/core/http/session_manager.cpp +++ b/core/http/session_manager.cpp @@ -216,7 +216,7 @@ void SessionManager::clear() { String SessionManager::generate_session_id(const String &base) { // todo make something simpler / better - SHA256 *h = SHA256::get(); + Ref h = SHA256::get(); String sid = base; sid += rand(); @@ -225,8 +225,6 @@ String SessionManager::generate_session_id(const String &base) { sid = h->get_hash(); sid.resize(20); - delete h; - return sid; }