diff --git a/AuthServ/AuthServer.cpp b/AuthServ/AuthServer.cpp index c901a25..e6acc91 100755 --- a/AuthServ/AuthServer.cpp +++ b/AuthServ/AuthServer.cpp @@ -619,15 +619,15 @@ void cb_downloadStart(AuthServer_Private& client) } filename = filename.replace("\\", "/"); - DS::Stream* stream; + std::unique_ptr stream; // Check to see if this is our special SDL file... if (DS::Settings::SendDescriptorDb() && filename.ends_with(".sdl", ST::case_sensitivity_t::case_insensitive)) { - stream = new DS::BlobStream(s_minifiedSdl); + stream = std::make_unique(s_minifiedSdl); } else { filename = DS::Settings::AuthRoot() + filename; - stream = new DS::FileStream(); + stream = std::make_unique(); try { - static_cast(stream)->open(filename.c_str(), "rb"); + static_cast(stream.get())->open(filename.c_str(), "rb"); } catch (const DS::FileIOException& ex) { ST::printf(stderr, "[Auth] Could not open file {}: {}\n[Auth] Requested by {}\n", filename, ex.what(), DS::SockIpAddress(client.m_sock)); @@ -636,7 +636,6 @@ void cb_downloadStart(AuthServer_Private& client) client.m_buffer.write(0); // Chunk offset client.m_buffer.write(0); // Data packet size SEND_REPLY(); - delete stream; return; } } @@ -649,12 +648,11 @@ void cb_downloadStart(AuthServer_Private& client) client.m_buffer.write(CHUNK_SIZE); uint8_t* data = client.m_buffer.allocate(CHUNK_SIZE); stream->readBytes(data, CHUNK_SIZE); - client.m_downloads[transId] = stream; + client.m_downloads[transId] = std::move(stream); } else { client.m_buffer.write(stream->size()); uint8_t* data = client.m_buffer.allocate(stream->size()); stream->readBytes(data, stream->size()); - delete stream; } SEND_REPLY(); @@ -687,7 +685,6 @@ void cb_downloadNext(AuthServer_Private& client) client.m_buffer.write(bytesLeft); uint8_t* data = client.m_buffer.allocate(bytesLeft); fi->second->readBytes(data, bytesLeft); - delete fi->second; client.m_downloads.erase(fi); } diff --git a/AuthServ/AuthServer_Private.h b/AuthServ/AuthServer_Private.h index dc31715..f58b59d 100644 --- a/AuthServ/AuthServer_Private.h +++ b/AuthServ/AuthServer_Private.h @@ -26,6 +26,7 @@ #include #include #include +#include enum AuthServer_MsgIds { @@ -105,17 +106,13 @@ struct AuthServer_Private : public AuthClient_Private uint32_t m_acctFlags; AuthServer_PlayerInfo m_player; uint32_t m_ageNodeId; - std::map m_downloads; + std::map> m_downloads; AuthServer_Private() : m_serverChallenge(0), m_acctFlags(0), m_ageNodeId(0) { } ~AuthServer_Private() { - while (!m_downloads.empty()) { - auto item = m_downloads.begin(); - delete item->second; - m_downloads.erase(item); - } + m_downloads.clear(); } };