From 9e032223eba7292bb61de6d3afd16c7ab7134184 Mon Sep 17 00:00:00 2001 From: Jett <55758076+Jettford@users.noreply.github.com> Date: Sun, 12 Dec 2021 15:53:19 +0000 Subject: [PATCH] Remove unused MD5 functions and fixed memory leak --- dCommon/MD5.cpp | 8 -------- dCommon/MD5.h | 1 - dWorldServer/WorldServer.cpp | 13 ++++++++----- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/dCommon/MD5.cpp b/dCommon/MD5.cpp index d20dbd6b..36c0d2cf 100644 --- a/dCommon/MD5.cpp +++ b/dCommon/MD5.cpp @@ -115,14 +115,6 @@ MD5::MD5(const std::string &text) finalize(); } -// raw md5 construstor -MD5::MD5(const char * input, size_type length) -{ - init(); - update(input, length); - finalize(); -} - ////////////////////////////// void MD5::init() diff --git a/dCommon/MD5.h b/dCommon/MD5.h index 3b84d6f8..1ada98a5 100644 --- a/dCommon/MD5.h +++ b/dCommon/MD5.h @@ -54,7 +54,6 @@ public: MD5(); MD5(const std::string& text); - MD5(const char * input, size_type length); void update(const unsigned char *buf, size_type length); void update(const char *buf, size_type length); MD5& finalize(); diff --git a/dWorldServer/WorldServer.cpp b/dWorldServer/WorldServer.cpp index 8cbb7276..9c3aa6b3 100644 --- a/dWorldServer/WorldServer.cpp +++ b/dWorldServer/WorldServer.cpp @@ -239,17 +239,20 @@ int main(int argc, char** argv) { // pre calculate the FDB checksum if (bool(std::stoi(Game::config->GetValue("check_fdb")))) { std::ifstream fileStream; - fileStream.open ("res/CDServer.fdb", std::ios::binary | std::ios::in); + fileStream.open("res/CDServer.fdb", std::ios::binary | std::ios::in); const int bufferSize = 1024; MD5* md5 = new MD5(); + std::vector fileStreamBuffer = std::vector(bufferSize, 0); + while (!fileStream.eof()) { - char * fileStreamBuffer = new char[bufferSize]; - fileStream.read(fileStreamBuffer, bufferSize); - std::streamsize size = ((fileStream) ? bufferSize : fileStream.gcount()); - md5->update(fileStreamBuffer, size); + fileStreamBuffer.clear(); + fileStream.read(fileStreamBuffer.data(), bufferSize); + md5->update(fileStreamBuffer.data(), fileStream.gcount()); } + fileStreamBuffer.clear(); + const char* nullTerminateBuffer = "\0"; md5->update(nullTerminateBuffer, 1); // null terminate the data md5->finalize();