Changeset - r25390:7b2cc712ea32
[Not reviewed]
master
0 3 0
rubidium42 - 3 years ago 2021-05-04 17:30:25
rubidium@openttd.org
Codechange: [Network] Use new/delete instead of calloc/free for NetworkGameList
3 files changed with 15 insertions and 15 deletions:
0 comments (0 inline, 0 general)
src/network/network_gamelist.cpp
Show inline comments
 
@@ -57,7 +57,7 @@ static void NetworkGameListHandleDelayed
 
			if (item->manually) NetworkRebuildHostList();
 
			UpdateNetworkGameWindow();
 
		}
 
		free(ins_item);
 
		delete ins_item;
 
	}
 
}
 

	
 
@@ -80,9 +80,7 @@ NetworkGameList *NetworkGameListAddItem(
 
		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(NetworkGa
 

	
 
			/* Remove GRFConfig information */
 
			ClearGRFConfigList(&remove->info.grfconfig);
 
			free(remove);
 
			remove = nullptr;
 
			delete remove;
 

	
 
			DEBUG(net, 4, "[gamelist] removed server from list");
 
			NetworkRebuildHostList();
src/network/network_gamelist.h
Show inline comments
 
@@ -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 */
src/network/network_udp.cpp
Show inline comments
 
@@ -90,10 +90,8 @@ static UDPSocket _udp_master("Master"); 
 
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);
0 comments (0 inline, 0 general)