Skip to content

Commit

Permalink
Don't manually memory manage AuthSrv downloads.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoikas committed Aug 27, 2023
1 parent 33e35c7 commit 0d7c79b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
13 changes: 5 additions & 8 deletions AuthServ/AuthServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,15 +619,15 @@ void cb_downloadStart(AuthServer_Private& client)
}
filename = filename.replace("\\", "/");

DS::Stream* stream;
std::unique_ptr<DS::Stream> 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<DS::BlobStream>(s_minifiedSdl);
} else {
filename = DS::Settings::AuthRoot() + filename;
stream = new DS::FileStream();
stream = std::make_unique<DS::FileStream>();
try {
static_cast<DS::FileStream*>(stream)->open(filename.c_str(), "rb");
static_cast<DS::FileStream*>(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));
Expand All @@ -636,7 +636,6 @@ void cb_downloadStart(AuthServer_Private& client)
client.m_buffer.write<uint32_t>(0); // Chunk offset
client.m_buffer.write<uint32_t>(0); // Data packet size
SEND_REPLY();
delete stream;
return;
}
}
Expand All @@ -649,12 +648,11 @@ void cb_downloadStart(AuthServer_Private& client)
client.m_buffer.write<uint32_t>(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<uint32_t>(stream->size());
uint8_t* data = client.m_buffer.allocate(stream->size());
stream->readBytes(data, stream->size());
delete stream;
}

SEND_REPLY();
Expand Down Expand Up @@ -687,7 +685,6 @@ void cb_downloadNext(AuthServer_Private& client)
client.m_buffer.write<uint32_t>(bytesLeft);
uint8_t* data = client.m_buffer.allocate(bytesLeft);
fi->second->readBytes(data, bytesLeft);
delete fi->second;
client.m_downloads.erase(fi);
}

Expand Down
9 changes: 3 additions & 6 deletions AuthServ/AuthServer_Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <unordered_map>
#include <thread>
#include <mutex>
#include <memory>

enum AuthServer_MsgIds
{
Expand Down Expand Up @@ -105,17 +106,13 @@ struct AuthServer_Private : public AuthClient_Private
uint32_t m_acctFlags;
AuthServer_PlayerInfo m_player;
uint32_t m_ageNodeId;
std::map<uint32_t, DS::Stream*> m_downloads;
std::map<uint32_t, std::unique_ptr<DS::Stream>> 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();
}
};

Expand Down

0 comments on commit 0d7c79b

Please sign in to comment.