Skip to content

Commit

Permalink
lsteamclient: Only free SteamMatchmakingServerListResponse callback a…
Browse files Browse the repository at this point in the history
…fter ISteamMatchMakingServers::ReleaseRequest().

And leak the callback for SteamMatchMakingServers v001
(same as before e3798c1 for both versions).

CW-Bug-Id: #24528
  • Loading branch information
Paul Gofman authored and ivyl committed Nov 28, 2024
1 parent 01c636d commit 7a651eb
Showing 1 changed file with 70 additions and 11 deletions.
81 changes: 70 additions & 11 deletions lsteamclient/unix_steam_networking_manual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#pragma makedep unix
#endif

#include <unordered_map>

WINE_DEFAULT_DEBUG_CHANNEL(steamclient);

static void receive_messages_utow_144( uint32_t count, u_SteamNetworkingMessage_t_144 **u_msgs,
Expand Down Expand Up @@ -600,6 +602,41 @@ template <typename T> void free_callback_obj(T *obj)
delete obj;
}



template <typename T> class callback_obj_tracker
{
std::unordered_map<void *, T *> tracked_objects;

public:
void request_released( void *hrequest )
{
auto entry = tracked_objects.find( hrequest );
if (entry == tracked_objects.end())
{
WARN( "Object not found for request %p.\n", hrequest );
return;
}
TRACE( "request %p, deleting %p.\n", hrequest, entry->second );
free_callback_obj( entry->second );
tracked_objects.erase( entry );
}

void add_request( void *hrequest, T *obj )
{
auto entry = tracked_objects.find( hrequest );

TRACE( "request %p, obj %p.\n", hrequest, obj );
if (entry == tracked_objects.end())
{
tracked_objects[hrequest] = obj;
return;
}
ERR( "hrequest %p already registered, old %p, new %p.\n", hrequest, entry->second, obj );
entry->second = obj;
}
};

struct SteamMatchmakingServerListResponse_099u : u_ISteamMatchmakingServerListResponse_099u
{
struct w_steam_iface *w_iface;
Expand All @@ -621,8 +658,7 @@ void SteamMatchmakingServerListResponse_099u::ServerFailedToRespond( int32_t iSe
void SteamMatchmakingServerListResponse_099u::RefreshComplete( uint32_t response )
{
queue_vtable_callback( this->w_iface, CALL_IFACE_VTABLE_2, (intptr_t)response, 0, 0 );
TRACE("Deleting this %p, w_iface %p.\n", this, this->w_iface);
free_callback_obj(this);
TRACE( "RefreshComplete this %p, w_iface %p.\n", this, this->w_iface );
}

u_ISteamMatchmakingServerListResponse_099u *create_LinuxISteamMatchmakingServerListResponse_099u( void *win )
Expand All @@ -641,10 +677,27 @@ u_ISteamMatchmakingServerListResponse_099u *create_LinuxISteamMatchmakingServerL
struct SteamMatchmakingServerListResponse_106 : u_ISteamMatchmakingServerListResponse_106
{
struct w_steam_iface *w_iface;
static class callback_obj_tracker<SteamMatchmakingServerListResponse_106> track;

void add_request( void *hrequest)
{
if (hrequest) track.add_request( hrequest, this );
else
{
WARN( "NULL request.\n" );
free_callback_obj( this );
}
}
static void request_released( void *hrequest )
{
track.request_released( hrequest );
}

virtual void ServerResponded( void *, int32_t );
virtual void ServerFailedToRespond( void *, int32_t );
virtual void RefreshComplete( void *, uint32_t );
};
class callback_obj_tracker<SteamMatchmakingServerListResponse_106> SteamMatchmakingServerListResponse_106::track;

void SteamMatchmakingServerListResponse_106::ServerResponded( void *hRequest, int32_t iServer )
{
Expand All @@ -659,11 +712,10 @@ void SteamMatchmakingServerListResponse_106::ServerFailedToRespond( void *hReque
void SteamMatchmakingServerListResponse_106::RefreshComplete( void *hRequest, uint32_t response )
{
queue_vtable_callback( this->w_iface, CALL_IFACE_VTABLE_2, (intptr_t)hRequest, (intptr_t)response, 0 );
TRACE("Deleting this %p, w_iface %p.\n", this, this->w_iface);
free_callback_obj(this);
TRACE( "RefreshComplete this %p, w_iface %p.\n", this, this->w_iface );
}

u_ISteamMatchmakingServerListResponse_106 *create_LinuxISteamMatchmakingServerListResponse_106( void *win )
SteamMatchmakingServerListResponse_106 *create_LinuxISteamMatchmakingServerListResponse_106( void *win )
{
SteamMatchmakingServerListResponse_106 *ret;

Expand Down Expand Up @@ -884,53 +936,59 @@ NTSTATUS ISteamMatchmakingServers_SteamMatchMakingServers002_RequestInternetServ
{
struct ISteamMatchmakingServers_SteamMatchMakingServers002_RequestInternetServerList_params *params = (struct ISteamMatchmakingServers_SteamMatchMakingServers002_RequestInternetServerList_params *)args;
struct u_ISteamMatchmakingServers_SteamMatchMakingServers002 *iface = (struct u_ISteamMatchmakingServers_SteamMatchMakingServers002 *)params->linux_side;
u_ISteamMatchmakingServerListResponse_106 *u_pRequestServersResponse = create_LinuxISteamMatchmakingServerListResponse_106( params->pRequestServersResponse );
SteamMatchmakingServerListResponse_106 *u_pRequestServersResponse = create_LinuxISteamMatchmakingServerListResponse_106( params->pRequestServersResponse );
params->_ret = iface->RequestInternetServerList( params->iApp, params->ppchFilters, params->nFilters, u_pRequestServersResponse );
u_pRequestServersResponse->add_request( params->_ret );
return 0;
}

NTSTATUS ISteamMatchmakingServers_SteamMatchMakingServers002_RequestLANServerList( void *args )
{
struct ISteamMatchmakingServers_SteamMatchMakingServers002_RequestLANServerList_params *params = (struct ISteamMatchmakingServers_SteamMatchMakingServers002_RequestLANServerList_params *)args;
struct u_ISteamMatchmakingServers_SteamMatchMakingServers002 *iface = (struct u_ISteamMatchmakingServers_SteamMatchMakingServers002 *)params->linux_side;
u_ISteamMatchmakingServerListResponse_106 *u_pRequestServersResponse = create_LinuxISteamMatchmakingServerListResponse_106( params->pRequestServersResponse );
SteamMatchmakingServerListResponse_106 *u_pRequestServersResponse = create_LinuxISteamMatchmakingServerListResponse_106( params->pRequestServersResponse );
params->_ret = iface->RequestLANServerList( params->iApp, u_pRequestServersResponse );
u_pRequestServersResponse->add_request( params->_ret );
return 0;
}

NTSTATUS ISteamMatchmakingServers_SteamMatchMakingServers002_RequestFriendsServerList( void *args )
{
struct ISteamMatchmakingServers_SteamMatchMakingServers002_RequestFriendsServerList_params *params = (struct ISteamMatchmakingServers_SteamMatchMakingServers002_RequestFriendsServerList_params *)args;
struct u_ISteamMatchmakingServers_SteamMatchMakingServers002 *iface = (struct u_ISteamMatchmakingServers_SteamMatchMakingServers002 *)params->linux_side;
u_ISteamMatchmakingServerListResponse_106 *u_pRequestServersResponse = create_LinuxISteamMatchmakingServerListResponse_106( params->pRequestServersResponse );
SteamMatchmakingServerListResponse_106 *u_pRequestServersResponse = create_LinuxISteamMatchmakingServerListResponse_106( params->pRequestServersResponse );
params->_ret = iface->RequestFriendsServerList( params->iApp, params->ppchFilters, params->nFilters, u_pRequestServersResponse );
u_pRequestServersResponse->add_request( params->_ret );
return 0;
}

NTSTATUS ISteamMatchmakingServers_SteamMatchMakingServers002_RequestFavoritesServerList( void *args )
{
struct ISteamMatchmakingServers_SteamMatchMakingServers002_RequestFavoritesServerList_params *params = (struct ISteamMatchmakingServers_SteamMatchMakingServers002_RequestFavoritesServerList_params *)args;
struct u_ISteamMatchmakingServers_SteamMatchMakingServers002 *iface = (struct u_ISteamMatchmakingServers_SteamMatchMakingServers002 *)params->linux_side;
u_ISteamMatchmakingServerListResponse_106 *u_pRequestServersResponse = create_LinuxISteamMatchmakingServerListResponse_106( params->pRequestServersResponse );
SteamMatchmakingServerListResponse_106 *u_pRequestServersResponse = create_LinuxISteamMatchmakingServerListResponse_106( params->pRequestServersResponse );
params->_ret = iface->RequestFavoritesServerList( params->iApp, params->ppchFilters, params->nFilters, u_pRequestServersResponse );
u_pRequestServersResponse->add_request( params->_ret );
return 0;
}

NTSTATUS ISteamMatchmakingServers_SteamMatchMakingServers002_RequestHistoryServerList( void *args )
{
struct ISteamMatchmakingServers_SteamMatchMakingServers002_RequestHistoryServerList_params *params = (struct ISteamMatchmakingServers_SteamMatchMakingServers002_RequestHistoryServerList_params *)args;
struct u_ISteamMatchmakingServers_SteamMatchMakingServers002 *iface = (struct u_ISteamMatchmakingServers_SteamMatchMakingServers002 *)params->linux_side;
u_ISteamMatchmakingServerListResponse_106 *u_pRequestServersResponse = create_LinuxISteamMatchmakingServerListResponse_106( params->pRequestServersResponse );
SteamMatchmakingServerListResponse_106 *u_pRequestServersResponse = create_LinuxISteamMatchmakingServerListResponse_106( params->pRequestServersResponse );
params->_ret = iface->RequestHistoryServerList( params->iApp, params->ppchFilters, params->nFilters, u_pRequestServersResponse );
u_pRequestServersResponse->add_request( params->_ret );
return 0;
}

NTSTATUS ISteamMatchmakingServers_SteamMatchMakingServers002_RequestSpectatorServerList( void *args )
{
struct ISteamMatchmakingServers_SteamMatchMakingServers002_RequestSpectatorServerList_params *params = (struct ISteamMatchmakingServers_SteamMatchMakingServers002_RequestSpectatorServerList_params *)args;
struct u_ISteamMatchmakingServers_SteamMatchMakingServers002 *iface = (struct u_ISteamMatchmakingServers_SteamMatchMakingServers002 *)params->linux_side;
u_ISteamMatchmakingServerListResponse_106 *u_pRequestServersResponse = create_LinuxISteamMatchmakingServerListResponse_106( params->pRequestServersResponse );
SteamMatchmakingServerListResponse_106 *u_pRequestServersResponse = create_LinuxISteamMatchmakingServerListResponse_106( params->pRequestServersResponse );
params->_ret = iface->RequestSpectatorServerList( params->iApp, params->ppchFilters, params->nFilters, u_pRequestServersResponse );
u_pRequestServersResponse->add_request( params->_ret );
return 0;
}

Expand Down Expand Up @@ -966,6 +1024,7 @@ NTSTATUS ISteamMatchmakingServers_SteamMatchMakingServers002_ReleaseRequest( voi
struct ISteamMatchmakingServers_SteamMatchMakingServers002_ReleaseRequest_params *params = (struct ISteamMatchmakingServers_SteamMatchMakingServers002_ReleaseRequest_params *)args;
struct u_ISteamMatchmakingServers_SteamMatchMakingServers002 *iface = (struct u_ISteamMatchmakingServers_SteamMatchMakingServers002 *)params->linux_side;
iface->ReleaseRequest( params->hServerListRequest );
SteamMatchmakingServerListResponse_106::request_released( params->hServerListRequest );
return 0;
}

Expand Down

0 comments on commit 7a651eb

Please sign in to comment.