int getPlayersCount() {
static int id = 3;
int result = -1;
rconpp::rcon_client client(rcon_credentials.ip, rcon_credentials.port, rcon_credentials.password);
client.on_log = [](const std::string_view& log) { std::cout << log << std::endl; };
client.start(true);
if (client.connected) {
auto response = client.send_data_sync("list", ++id, rconpp::data_type::SERVERDATA_EXECCOMMAND);
/* ... */
std::cout << response.data << std::endl;
}
return result;
}
int main() {
ABMinecraft minecraft(Settings::rcon_credentials);
minecraft.getPlayersCount();
std::cout << "exited getPlayersCount(), rcon_client is destructed" << std::endl;
while (true) {
}
}
The program crashes a moment after the rcon_client is destructed:
I think the problem is that queue_runner uses this->connected after the rcon_client object is destructed, and even if bool connected was set to false in the destructor, it may not be false after the memory is freed.
I am using your library as follows:
The program crashes a moment after the rcon_client is destructed: I think the problem is that
queue_runner
usesthis->connected
after the rcon_client object is destructed, and even ifbool connected
was set to false in the destructor, it may not be false after the memory is freed.For a possible fix, see PR.