From c8e00cd64d3a4b16370fa9cecb7129bc33f45555 Mon Sep 17 00:00:00 2001 From: Intel Date: Mon, 5 May 2014 11:39:51 -0400 Subject: [PATCH] Leak fix --- src/server/poolserver/Stratum/Client.cpp | 1 - src/server/poolserver/Stratum/Client.h | 3 --- src/server/poolserver/Stratum/ShareLimiter.cpp | 7 +++++-- src/server/shared/Bitcoin/Bitcoin.h | 4 +++- src/server/shared/JSON/JSONReader.h | 8 ++++++++ src/server/shared/MySQL/DatabaseConnection.h | 2 +- src/server/shared/MySQL/DatabaseOperation.cpp | 4 ++-- src/server/shared/MySQL/DatabaseOperation.h | 13 +++---------- src/server/shared/MySQL/DatabaseWorkerPool.h | 2 +- 9 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/server/poolserver/Stratum/Client.cpp b/src/server/poolserver/Stratum/Client.cpp index 4029dc2..392af9a 100644 --- a/src/server/poolserver/Stratum/Client.cpp +++ b/src/server/poolserver/Stratum/Client.cpp @@ -359,7 +359,6 @@ namespace Stratum sLog.Error(LOG_SERVER, "Exception caught while parsing json: %s", e.what()); } _recvMessage.clear(); - _recvMessage.reserve(PACKET_ALLOC); } else _recvMessage += c; } diff --git a/src/server/poolserver/Stratum/Client.h b/src/server/poolserver/Stratum/Client.h index a929f34..ff873aa 100644 --- a/src/server/poolserver/Stratum/Client.h +++ b/src/server/poolserver/Stratum/Client.h @@ -15,8 +15,6 @@ #include #include -#define PACKET_ALLOC 128 - using namespace boost; using namespace boost::asio::ip; @@ -31,7 +29,6 @@ namespace Stratum { _diff = sConfig.Get("StratumMinDifficulty"); _minDiff = _diff; - _recvMessage.reserve(PACKET_ALLOC); } tcp::socket& GetSocket() diff --git a/src/server/poolserver/Stratum/ShareLimiter.cpp b/src/server/poolserver/Stratum/ShareLimiter.cpp index 3cad777..d291296 100644 --- a/src/server/poolserver/Stratum/ShareLimiter.cpp +++ b/src/server/poolserver/Stratum/ShareLimiter.cpp @@ -21,11 +21,14 @@ namespace Stratum _lastRetarget = curTime; // Check if miner is ok - if (_totalShares > 20 && (double(_totalBadShares)/double(_totalShares)) > 0.8) + if (_totalShares > 50 && (double(_totalBadShares)/double(_totalShares)) > 0.8) _client->Ban(60); - while (_shares.size() && (_shares.front() < curTime - RETARGET_TIME_BUFFER)) + while (_shares.size()) { + if (_shares.front() > curTime - RETARGET_TIME_BUFFER) + break; _shares.pop_front(); + } uint32 interval = std::min(curTime - _startTime, uint64(RETARGET_TIME_BUFFER)); diff --git a/src/server/shared/Bitcoin/Bitcoin.h b/src/server/shared/Bitcoin/Bitcoin.h index eadf469..af2e344 100644 --- a/src/server/shared/Bitcoin/Bitcoin.h +++ b/src/server/shared/Bitcoin/Bitcoin.h @@ -28,7 +28,9 @@ namespace Bitcoin mpz_t power; mpz_init(power); mpz_ui_pow_ui(power, 2, 8 * (nbytes - 3)); - return BigInt(bits & 0xFFFFFF) * BigInt(power); + BigInt result = BigInt(bits & 0xFFFFFF) * BigInt(power); + mpz_clear(power); + return result; } inline Transaction CreateCoinbaseTX(uint32 blockHeight, BinaryData pubkey, int64 value) diff --git a/src/server/shared/JSON/JSONReader.h b/src/server/shared/JSON/JSONReader.h index 1af48a0..fa66894 100644 --- a/src/server/shared/JSON/JSONReader.h +++ b/src/server/shared/JSON/JSONReader.h @@ -22,6 +22,14 @@ namespace JSONReader _stack.push_back(&node); } + ~SemanticFunctions() + { + for (uint32 i = 0; i+1 < _stack.size(); ++i) { + delete _stack.back(); + _stack.pop_back(); + } + } + void BeginObject(char ch) { if (_stack.back()->GetType() == JSON_NULL) diff --git a/src/server/shared/MySQL/DatabaseConnection.h b/src/server/shared/MySQL/DatabaseConnection.h index a9936b6..08bedd8 100644 --- a/src/server/shared/MySQL/DatabaseConnection.h +++ b/src/server/shared/MySQL/DatabaseConnection.h @@ -87,7 +87,7 @@ namespace MySQL char* buf = new char[text.length()*2 + 1]; mysql_real_escape_string(_mysql, buf, text.c_str(), text.length()); std::string result(buf); - delete buf; + delete[] buf; return result; } diff --git a/src/server/shared/MySQL/DatabaseOperation.cpp b/src/server/shared/MySQL/DatabaseOperation.cpp index d3598df..63dd8fb 100644 --- a/src/server/shared/MySQL/DatabaseOperation.cpp +++ b/src/server/shared/MySQL/DatabaseOperation.cpp @@ -21,9 +21,9 @@ namespace MySQL void DatabaseQueryOperation::Execute() { if (_callback) { - ResultSet* result = _conn->Query(_query); + ResultSet* result = _conn->Query(_query.c_str()); _callback(QueryResult(result)); } else - _conn->Execute(_query); + _conn->Execute(_query.c_str()); } } diff --git a/src/server/shared/MySQL/DatabaseOperation.h b/src/server/shared/MySQL/DatabaseOperation.h index ccc953a..3e8f05b 100644 --- a/src/server/shared/MySQL/DatabaseOperation.h +++ b/src/server/shared/MySQL/DatabaseOperation.h @@ -40,22 +40,15 @@ namespace MySQL class DatabaseQueryOperation : public DatabaseOperation { public: - DatabaseQueryOperation(const char* query, DatabaseCallback callback = NULL): DatabaseOperation(), _callback(callback) - { - _query = new char[strlen(query)]; - strcpy(_query, const_cast(query)); - } + DatabaseQueryOperation(const char* query, DatabaseCallback callback = NULL): DatabaseOperation(), _callback(callback), _query(query) {} - ~DatabaseQueryOperation() - { - delete[] _query; - } + ~DatabaseQueryOperation() {} void Execute(); private: DatabaseCallback _callback; - char* _query; + std::string _query; }; typedef Util::SynchronisedQueue DatabaseWorkQueue; diff --git a/src/server/shared/MySQL/DatabaseWorkerPool.h b/src/server/shared/MySQL/DatabaseWorkerPool.h index c8f1dc4..62dd709 100644 --- a/src/server/shared/MySQL/DatabaseWorkerPool.h +++ b/src/server/shared/MySQL/DatabaseWorkerPool.h @@ -104,7 +104,7 @@ namespace MySQL private: DatabaseConnection* GetSyncConnection() { - uint32 i; + uint32 i = 0; uint8 conn_size = _connections[MYSQL_CONN_SYNC].size(); DatabaseConnection* conn = NULL;