From: Anton Baskanov baskanov@gmail.com
--- dlls/dplayx/dplay.c | 45 ++++++++++++++++++++++---------------- dlls/dplayx/dplay_global.h | 1 + dlls/dplayx/name_server.c | 17 +++++--------- 3 files changed, 33 insertions(+), 30 deletions(-)
diff --git a/dlls/dplayx/dplay.c b/dlls/dplayx/dplay.c index f0560fadd4e..125d50c5524 100644 --- a/dlls/dplayx/dplay.c +++ b/dlls/dplayx/dplay.c @@ -69,7 +69,7 @@ static BOOL DP_BuildSPCompoundAddr( LPGUID lpcSpGuid, LPVOID* lplpAddrBuf, static DPID DP_GetRemoteNextObjectId(void);
static DWORD DP_CopySessionDesc( LPDPSESSIONDESC2 destSessionDesc, - LPCDPSESSIONDESC2 srcSessDesc, BOOL bAnsi ); + LPCDPSESSIONDESC2 srcSessDesc, BOOL dstAnsi, BOOL srcAnsi );
#define DPID_NOPARENT_GROUP 0 /* Magic number to indicate no parent of group */ @@ -3185,7 +3185,7 @@ static HRESULT DP_GetSessionDesc( IDirectPlayImpl *This, void *lpData, DWORD *lp return DPERR_INVALIDPARAMS; }
- dwRequiredSize = DP_CopySessionDesc( NULL, This->dp2->lpSessionDesc, bAnsi ); + dwRequiredSize = DP_CopySessionDesc( NULL, This->dp2->lpSessionDesc, bAnsi, bAnsi );
if ( ( lpData == NULL ) || ( *lpdwDataSize < dwRequiredSize ) @@ -3195,7 +3195,7 @@ static HRESULT DP_GetSessionDesc( IDirectPlayImpl *This, void *lpData, DWORD *lp return DPERR_BUFFERTOOSMALL; }
- DP_CopySessionDesc( lpData, This->dp2->lpSessionDesc, bAnsi ); + DP_CopySessionDesc( lpData, This->dp2->lpSessionDesc, bAnsi, bAnsi );
return DP_OK; } @@ -3851,7 +3851,6 @@ static HRESULT WINAPI IDirectPlay4Impl_SetPlayerName( IDirectPlay4 *iface, DPID static HRESULT DP_SetSessionDesc( IDirectPlayImpl *This, const DPSESSIONDESC2 *lpSessDesc, DWORD dwFlags, BOOL bInitial, BOOL bAnsi ) { - DWORD dwRequiredSize; LPDPSESSIONDESC2 lpTempSessDesc;
TRACE( "(%p)->(%p,0x%08lx,%u,%u)\n", @@ -3873,9 +3872,7 @@ static HRESULT DP_SetSessionDesc( IDirectPlayImpl *This, const DPSESSIONDESC2 *l return DPERR_ACCESSDENIED; }
- /* FIXME: Copy into This->dp2->lpSessionDesc */ - dwRequiredSize = DP_CopySessionDesc( NULL, lpSessDesc, bAnsi ); - lpTempSessDesc = calloc( 1, dwRequiredSize ); + lpTempSessDesc = DP_DuplicateSessionDesc( lpSessDesc, bAnsi, bAnsi );
if( lpTempSessDesc == NULL ) { @@ -3886,13 +3883,7 @@ static HRESULT DP_SetSessionDesc( IDirectPlayImpl *This, const DPSESSIONDESC2 *l free( This->dp2->lpSessionDesc );
This->dp2->lpSessionDesc = lpTempSessDesc; - /* Set the new */ - DP_CopySessionDesc( This->dp2->lpSessionDesc, lpSessDesc, bAnsi ); - if( bInitial ) - { - /*Initializing session GUID*/ - CoCreateGuid( &(This->dp2->lpSessionDesc->guidInstance) ); - } + /* If this is an external invocation of the interface, we should be * letting everyone know that things have changed. Otherwise this is * just an initialization and it doesn't need to be propagated. @@ -3948,21 +3939,37 @@ static HRESULT WINAPI IDirectPlay4Impl_SetSessionDesc( IDirectPlay4 *iface, }
static DWORD DP_CopySessionDesc( LPDPSESSIONDESC2 lpSessionDest, - LPCDPSESSIONDESC2 lpSessionSrc, BOOL bAnsi ) + LPCDPSESSIONDESC2 lpSessionSrc, BOOL dstAnsi, BOOL srcAnsi ) { DWORD offset = sizeof( DPSESSIONDESC2 );
if( lpSessionDest ) CopyMemory( lpSessionDest, lpSessionSrc, sizeof( *lpSessionSrc ) );
- offset += DP_CopyString( &lpSessionDest->lpszSessionNameA, lpSessionSrc->lpszSessionNameA, bAnsi, - bAnsi, lpSessionDest, offset ); - offset += DP_CopyString( &lpSessionDest->lpszPasswordA, lpSessionSrc->lpszPasswordA, bAnsi, - bAnsi, lpSessionDest, offset ); + offset += DP_CopyString( &lpSessionDest->lpszSessionNameA, lpSessionSrc->lpszSessionNameA, + dstAnsi, srcAnsi, lpSessionDest, offset ); + offset += DP_CopyString( &lpSessionDest->lpszPasswordA, lpSessionSrc->lpszPasswordA, + dstAnsi, srcAnsi, lpSessionDest, offset );
return offset; }
+DPSESSIONDESC2 *DP_DuplicateSessionDesc( const DPSESSIONDESC2 *src, BOOL dstAnsi, BOOL srcAnsi ) +{ + DPSESSIONDESC2 *dst; + DWORD size; + + size = DP_CopySessionDesc( NULL, src, dstAnsi, srcAnsi ); + + dst = malloc( size ); + if ( !dst ) + return NULL; + + DP_CopySessionDesc( dst, src, dstAnsi, srcAnsi ); + + return dst; +} + static HRESULT WINAPI IDirectPlay3AImpl_AddGroupToGroup( IDirectPlay3A *iface, DPID parent, DPID group ) { diff --git a/dlls/dplayx/dplay_global.h b/dlls/dplayx/dplay_global.h index 097f0839d84..6536d9e3f9c 100644 --- a/dlls/dplayx/dplay_global.h +++ b/dlls/dplayx/dplay_global.h @@ -200,6 +200,7 @@ typedef struct IDirectPlayImpl HRESULT DP_HandleMessage( IDirectPlayImpl *This, const void *lpMessageBody, DWORD dwMessageBodySize, const void *lpMessageHeader, WORD wCommandId, WORD wVersion, void **lplpReply, DWORD *lpdwMsgSize ); +DPSESSIONDESC2 *DP_DuplicateSessionDesc( const DPSESSIONDESC2 *src, BOOL dstAnsi, BOOL srcAnsi );
/* DP SP external interfaces into DirectPlay */ extern HRESULT DP_GetSPPlayerData( IDirectPlayImpl *lpDP, DPID idPlayer, void **lplpData ); diff --git a/dlls/dplayx/name_server.c b/dlls/dplayx/name_server.c index 44af9a8d566..3ea895c269d 100644 --- a/dlls/dplayx/name_server.c +++ b/dlls/dplayx/name_server.c @@ -92,9 +92,9 @@ void NS_AddRemoteComputerAsNameServer( LPCVOID lpcNSAddrHdr DWORD msgSize, LPVOID lpNSInfo ) { - DWORD len; lpNSCache lpCache = (lpNSCache)lpNSInfo; lpNSCacheData lpCacheNode; + DPSESSIONDESC2 dpsd; DWORD maxNameLength; DWORD nameLength;
@@ -131,7 +131,11 @@ void NS_AddRemoteComputerAsNameServer( LPCVOID lpcNSAddrHdr lpCacheNode->lpNSAddrHdr = malloc( dwHdrSize ); CopyMemory( lpCacheNode->lpNSAddrHdr, lpcNSAddrHdr, dwHdrSize );
- lpCacheNode->data = calloc( 1, sizeof( *(lpCacheNode->data) ) ); + dpsd = lpcMsg->sd; + dpsd.lpszSessionName = (WCHAR *) (lpcMsg + 1); + dpsd.lpszPassword = NULL; + + lpCacheNode->data = DP_DuplicateSessionDesc( &dpsd, TRUE, FALSE );
if( lpCacheNode->data == NULL ) { @@ -140,14 +144,6 @@ void NS_AddRemoteComputerAsNameServer( LPCVOID lpcNSAddrHdr return; }
- *lpCacheNode->data = lpcMsg->sd; - len = WideCharToMultiByte( CP_ACP, 0, (LPCWSTR)(lpcMsg+1), -1, NULL, 0, NULL, NULL ); - if ((lpCacheNode->data->lpszSessionNameA = malloc( len ))) - { - WideCharToMultiByte( CP_ACP, 0, (LPCWSTR)(lpcMsg+1), -1, - lpCacheNode->data->lpszSessionNameA, len, NULL, NULL ); - } - lpCacheNode->ref = 1; lpCacheNode->dwTime = timeGetTime();
@@ -242,7 +238,6 @@ static DPQ_DECL_DELETECB( cbReleaseNSNode, lpNSCacheData ) if ( ref ) return;
- /* FIXME: Memory leak on data (contained ptrs) */ free( elem->data ); free( elem->lpNSAddrHdr ); free( elem );