Skip to content
Snippets Groups Projects
Commit 560e511b authored by Carsten Patzke's avatar Carsten Patzke
Browse files

[Receiver] Fixed use after free bug

parent f5ca6f0c
No related branches found
No related tags found
No related merge requests found
......@@ -20,13 +20,18 @@ asapo::Error ReadConfigFile(int argc, char* argv[]) {
return factory.SetConfig(argv[1]);
}
void AddDataServers(const asapo::ReceiverConfig* config, asapo::SharedCache cache,
std::vector<asapo::RdsNetServerPtr>& netServers) {
// Add TCP
netServers.emplace_back(new asapo::RdsTcpServer("0.0.0.0:" + std::to_string(config->dataserver.listen_port)));
}
std::vector<std::thread> StartDataServers(const asapo::ReceiverConfig* config, asapo::SharedCache cache,
asapo::Error* error) {
std::vector<asapo::RdsNetServerPtr> netServers;
std::vector<std::thread> dataServerThreads;
// Add TCP
netServers.emplace_back(new asapo::RdsTcpServer("0.0.0.0:" + std::to_string(config->dataserver.listen_port)));
AddDataServers(config, cache, netServers);
for (auto& server : netServers) {
*error = server->Initialize();
......@@ -37,13 +42,15 @@ std::vector<std::thread> StartDataServers(const asapo::ReceiverConfig* config, a
dataServerThreads.reserve(netServers.size());
for (auto& server : netServers) {
dataServerThreads.emplace_back(std::thread([config, cache, &server] {
asapo::ReceiverDataServer data_server{
std::move(server),
config->log_level,
cache,
config->dataserver};
data_server.Run();
// Allocate the server here in order to make sure all variables are still available
auto data_server = new asapo::ReceiverDataServer{
std::move(server),
config->log_level,
cache,
config->dataserver};
dataServerThreads.emplace_back(std::thread([data_server] {
// We use a std::unique_ptr here in order to clean up the data_server once Run() is done.
std::unique_ptr<asapo::ReceiverDataServer>(data_server)->Run();
}));
}
......
......@@ -20,6 +20,7 @@ class ReceiverDataServer {
public:
explicit ReceiverDataServer(std::unique_ptr<RdsNetServer> net_server, LogLevel log_level, SharedCache data_cache,
const ReceiverDataServerConfig& config);
std::unique_ptr<RequestPool> request_pool__;
std::unique_ptr<RdsNetServer> net__;
const AbstractLogger* log__;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment