From 27699207f857e06ac23707b55325565a2790e878 Mon Sep 17 00:00:00 2001 From: dec05eba <0xdec05eba@gmail.com> Date: Tue, 22 May 2018 03:39:19 +0200 Subject: Follow cppcheck suggestions --- include/odhtdb/Database.hpp | 10 +++++++++- src/Database.cpp | 2 +- tests/main.cpp | 17 +++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/include/odhtdb/Database.hpp b/include/odhtdb/Database.hpp index a5fcb60..5ec0da0 100644 --- a/include/odhtdb/Database.hpp +++ b/include/odhtdb/Database.hpp @@ -142,6 +142,14 @@ namespace odhtdb requestOldDataListenerFuture = other.requestOldDataListenerFuture; reponseKeyInfoHash = other.reponseKeyInfoHash; } + DatabaseSeedInfo& operator=(const DatabaseSeedInfo &other) + { + newDataListenerFuture = other.newDataListenerFuture; + responseKeyFuture = other.responseKeyFuture; + requestOldDataListenerFuture = other.requestOldDataListenerFuture; + reponseKeyInfoHash = other.reponseKeyInfoHash; + return *this; + } }; using CreateNodeCallbackFunc = std::function; @@ -178,7 +186,7 @@ namespace odhtdb // Throws PermissionDeniedException if user @userToPerformActionWith is not allowed to add user @userToAdd to group @groupToAddUserTo void addUser(const DatabaseNode &nodeInfo, const Signature::KeyPair &userToPerformActionWith, const Signature::PublicKey &userToAddPublicKey, const DataView &groupToAddUserTo); - ntp::NtpTimestamp getSyncedTimestampUtc() const; + static ntp::NtpTimestamp getSyncedTimestampUtc(); bool doesStoredUserExist(const std::string &username) const; diff --git a/src/Database.cpp b/src/Database.cpp index 8d32240..a05aae6 100644 --- a/src/Database.cpp +++ b/src/Database.cpp @@ -555,7 +555,7 @@ namespace odhtdb nodePutWithRetry(&node, dhtKey.getNewDataListenerKey(), addDataValue); } - ntp::NtpTimestamp Database::getSyncedTimestampUtc() const + ntp::NtpTimestamp Database::getSyncedTimestampUtc() { while(!timestampSynced) { diff --git a/tests/main.cpp b/tests/main.cpp index 6a74548..17348c4 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -384,6 +384,22 @@ void testMemoryUsage() } } +pair> __attribute__((optimize("O0"))) getDataNoCopy() +{ + u8 *decryptionKeyRawCopy = new u8[1024 * 1024 * 64]; + memcpy(decryptionKeyRawCopy, "hello, world!", 14); + shared_ptr decryptionKey = make_shared(decryptionKeyRawCopy, ENCRYPTION_KEY_BYTE_SIZE); + return make_pair(true, decryptionKey); +} + +void __attribute__((optimize("O0"))) testMemoryLeak() +{ + { + auto data = getDataNoCopy(); + printf("data: %s\n", data.second->data); + } +} + struct Test { function testFunc; @@ -396,6 +412,7 @@ int main(int argc, char **argv) testByName["standard"] = { testStandard, false }; testByName["two_local_nodes"] = { testTwoLocalNodes, false }; testByName["memory_usage"] = { testMemoryUsage, true }; + testByName["test_memory_leak"] = { testMemoryLeak, true }; const char *testName = "all"; if(argc > 1) -- cgit v1.2.3