mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: [Network] Use new/delete instead of calloc/free for NetworkGameList
This commit is contained in:
parent
dc05917287
commit
dcef3209a6
|
@ -57,7 +57,7 @@ static void NetworkGameListHandleDelayedInsert()
|
|||
if (item->manually) NetworkRebuildHostList();
|
||||
UpdateNetworkGameWindow();
|
||||
}
|
||||
free(ins_item);
|
||||
delete ins_item;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,9 +80,7 @@ NetworkGameList *NetworkGameListAddItem(const std::string &connection_string)
|
|||
prev_item = item;
|
||||
}
|
||||
|
||||
item = CallocT<NetworkGameList>(1);
|
||||
item->next = nullptr;
|
||||
item->connection_string = resolved_connection_string;
|
||||
item = new NetworkGameList(resolved_connection_string);
|
||||
|
||||
if (prev_item == nullptr) {
|
||||
_network_game_list = item;
|
||||
|
@ -112,8 +110,7 @@ void NetworkGameListRemoveItem(NetworkGameList *remove)
|
|||
|
||||
/* Remove GRFConfig information */
|
||||
ClearGRFConfigList(&remove->info.grfconfig);
|
||||
free(remove);
|
||||
remove = nullptr;
|
||||
delete remove;
|
||||
|
||||
DEBUG(net, 4, "[gamelist] removed server from list");
|
||||
NetworkRebuildHostList();
|
||||
|
|
|
@ -16,12 +16,17 @@
|
|||
|
||||
/** Structure with information shown in the game list (GUI) */
|
||||
struct NetworkGameList {
|
||||
NetworkGameInfo info; ///< The game information of this server
|
||||
std::string connection_string; ///< Address of the server
|
||||
bool online; ///< False if the server did not respond (default status)
|
||||
bool manually; ///< True if the server was added manually
|
||||
uint8 retries; ///< Number of retries (to stop requerying)
|
||||
NetworkGameList *next; ///< Next pointer to make a linked game list
|
||||
NetworkGameList(const std::string &connection_string, bool manually = false) :
|
||||
connection_string(connection_string), manually(manually)
|
||||
{
|
||||
}
|
||||
|
||||
NetworkGameInfo info = {}; ///< The game information of this server
|
||||
std::string connection_string; ///< Address of the server
|
||||
bool online = false; ///< False if the server did not respond (default status)
|
||||
bool manually = false; ///< True if the server was added manually
|
||||
uint8 retries = 0; ///< Number of retries (to stop requerying)
|
||||
NetworkGameList *next = nullptr; ///< Next pointer to make a linked game list
|
||||
};
|
||||
|
||||
/** Game list of this client */
|
||||
|
|
|
@ -90,10 +90,8 @@ static UDPSocket _udp_master("Master"); ///< udp master socket
|
|||
static void DoNetworkUDPQueryServer(const std::string &connection_string, bool needs_mutex, bool manually)
|
||||
{
|
||||
/* Clear item in gamelist */
|
||||
NetworkGameList *item = CallocT<NetworkGameList>(1);
|
||||
NetworkGameList *item = new NetworkGameList(connection_string, manually);
|
||||
strecpy(item->info.server_name, connection_string.c_str(), lastof(item->info.server_name));
|
||||
item->connection_string = connection_string;
|
||||
item->manually = manually;
|
||||
NetworkGameListAddItemDelayed(item);
|
||||
|
||||
std::unique_lock<std::mutex> lock(_udp_client.mutex, std::defer_lock);
|
||||
|
|
Loading…
Reference in New Issue