Skip to content

Commit 2914f27

Browse files
committed
Don't manually memory manage AuthSrv downloads.
1 parent 2f1595b commit 2914f27

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

AuthServ/AuthServer.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -620,15 +620,15 @@ void cb_downloadStart(AuthServer_Private& client)
620620
}
621621
filename = filename.replace("\\", "/");
622622

623-
DS::Stream* stream;
623+
std::unique_ptr<DS::Stream> stream;
624624
// Check to see if this is our special SDL file...
625625
if (DS::Settings::SendDescriptorDb() && filename.ends_with(".sdl", ST::case_sensitivity_t::case_insensitive)) {
626-
stream = new DS::BlobStream(s_minifiedSdl);
626+
stream = std::make_unique<DS::BlobStream>(s_minifiedSdl);
627627
} else {
628628
filename = DS::Settings::AuthRoot() + filename;
629-
stream = new DS::FileStream();
629+
stream = std::make_unique<DS::FileStream>();
630630
try {
631-
static_cast<DS::FileStream*>(stream)->open(filename.c_str(), "rb");
631+
static_cast<DS::FileStream*>(stream.get())->open(filename.c_str(), "rb");
632632
} catch (const DS::FileIOException& ex) {
633633
ST::printf(stderr, "[Auth] Could not open file {}: {}\n[Auth] Requested by {}\n",
634634
filename, ex.what(), DS::SockIpAddress(client.m_sock));
@@ -637,7 +637,6 @@ void cb_downloadStart(AuthServer_Private& client)
637637
client.m_buffer.write<uint32_t>(0); // Chunk offset
638638
client.m_buffer.write<uint32_t>(0); // Data packet size
639639
SEND_REPLY();
640-
delete stream;
641640
return;
642641
}
643642
}
@@ -650,12 +649,11 @@ void cb_downloadStart(AuthServer_Private& client)
650649
client.m_buffer.write<uint32_t>(CHUNK_SIZE);
651650
uint8_t* data = client.m_buffer.allocate(CHUNK_SIZE);
652651
stream->readBytes(data, CHUNK_SIZE);
653-
client.m_downloads[transId] = stream;
652+
client.m_downloads[transId] = std::move(stream);
654653
} else {
655654
client.m_buffer.write<uint32_t>(stream->size());
656655
uint8_t* data = client.m_buffer.allocate(stream->size());
657656
stream->readBytes(data, stream->size());
658-
delete stream;
659657
}
660658

661659
SEND_REPLY();
@@ -688,7 +686,6 @@ void cb_downloadNext(AuthServer_Private& client)
688686
client.m_buffer.write<uint32_t>(bytesLeft);
689687
uint8_t* data = client.m_buffer.allocate(bytesLeft);
690688
fi->second->readBytes(data, bytesLeft);
691-
delete fi->second;
692689
client.m_downloads.erase(fi);
693690
}
694691

AuthServ/AuthServer_Private.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <unordered_map>
2727
#include <thread>
2828
#include <mutex>
29+
#include <memory>
2930

3031
enum AuthServer_MsgIds
3132
{
@@ -105,17 +106,13 @@ struct AuthServer_Private : public AuthClient_Private
105106
uint32_t m_acctFlags;
106107
AuthServer_PlayerInfo m_player;
107108
uint32_t m_ageNodeId;
108-
std::map<uint32_t, DS::Stream*> m_downloads;
109+
std::map<uint32_t, std::unique_ptr<DS::Stream>> m_downloads;
109110

110111
AuthServer_Private() : m_serverChallenge(0), m_acctFlags(0), m_ageNodeId(0) { }
111112

112113
~AuthServer_Private()
113114
{
114-
while (!m_downloads.empty()) {
115-
auto item = m_downloads.begin();
116-
delete item->second;
117-
m_downloads.erase(item);
118-
}
115+
m_downloads.clear();
119116
}
120117
};
121118

0 commit comments

Comments
 (0)