Skip to content

Commit 944625d

Browse files
committed
fixed:memoryleak problem that p2p get ip information
modify:p2p can be auto fill public address
1 parent d1165ca commit 944625d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

XEngine_Source/XEngine_StorageApp/StorageApp_P2XPNet.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ BOOL XEngine_Task_TCPP2xp(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, LPCTSTR lpszClie
6262
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("P2XP客户端:%s,处理登录错误,解析协议失败,错误码:%lX"), lpszClientAddr, Protocol_GetLastError());
6363
return FALSE;
6464
}
65+
//如果没有填充公用地址,用他的连接地址代替,外网服务器都可以这样做
66+
if (_tcslen(st_ClientPeer.st_PeerAddr.tszPublicAddr) <= 0)
67+
{
68+
_tcscpy(st_ClientPeer.st_PeerAddr.tszPublicAddr, lpszClientAddr);
69+
BaseLib_OperatorIPAddr_SegAddr(st_ClientPeer.st_PeerAddr.tszPublicAddr, NULL);
70+
}
6571
//获取外网IP所在位置
6672
int nBLen = 0;
6773
TCHAR* ptszBody;
@@ -70,7 +76,11 @@ BOOL XEngine_Task_TCPP2xp(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, LPCTSTR lpszClie
7076

7177
_stprintf(tszUrlBuffer, _T("http://app.xyry.org:5501/api?function=ipquery&params1=%s&params2=0"), st_ClientPeer.st_PeerAddr.tszPublicAddr);
7278
APIHelp_HttpRequest_Get(tszUrlBuffer, &ptszBody, &nBLen);
73-
APIHelp_Api_GetIPInfo(ptszBody, nBLen, &st_ClientPeer.st_IPAddrInfo);
79+
if (nBLen > 0)
80+
{
81+
APIHelp_Api_GetIPInfo(ptszBody, nBLen, &st_ClientPeer.st_IPAddrInfo);
82+
BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszBody);
83+
}
7484
st_ClientPeer.st_PeerTimer.dwUserTime = time(NULL);
7585
st_ClientPeer.st_PeerTimer.dwKeepAlive = time(NULL);
7686
st_ClientPeer.bIsLogin = TRUE;

0 commit comments

Comments
 (0)