mirror of
https://gitee.com/openharmony/communication_dsoftbus
synced 2024-11-28 03:10:48 +00:00
FastTransData is not released
Signed-off-by: erliangqi <zhangjiaxiang7@huawei.com>
This commit is contained in:
parent
92ce939ed6
commit
11e7e57dde
@ -327,6 +327,9 @@ void TransProxyDelChanByChanId(int32_t chanlId)
|
||||
if (item->channelId == chanlId) {
|
||||
ReleaseProxyChannelId(item->channelId);
|
||||
ListDelete(&(item->node));
|
||||
if (item->appInfo.fastTransData != NULL) {
|
||||
SoftBusFree((void *)item->appInfo.fastTransData);
|
||||
}
|
||||
SoftBusFree(item);
|
||||
g_proxyChannelList->cnt--;
|
||||
break;
|
||||
@ -389,6 +392,10 @@ static void TransProxyReleaseChannelList(ListNode *proxyChannelList, int32_t err
|
||||
} else {
|
||||
OnProxyChannelClosed(removeNode->channelId, &(removeNode->appInfo));
|
||||
}
|
||||
if (removeNode->appInfo.fastTransData != NULL) {
|
||||
SoftBusFree((void *)removeNode->appInfo.fastTransData);
|
||||
}
|
||||
SoftBusFree(removeNode);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1467,6 +1474,24 @@ void TransProxyonMessageReceived(const ProxyMessage *msg)
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t CopyAppInfoFastTransData(ProxyChannelInfo *chan, const AppInfo *appInfo)
|
||||
{
|
||||
if (appInfo->fastTransData != NULL && appInfo->fastTransDataSize > 0) {
|
||||
uint8_t *fastTransData = (uint8_t *)SoftBusCalloc(appInfo->fastTransDataSize);
|
||||
if (fastTransData == NULL) {
|
||||
return SOFTBUS_MALLOC_ERR;
|
||||
}
|
||||
if (memcpy_s((char *)fastTransData, appInfo->fastTransDataSize, (const char *)appInfo->fastTransData,
|
||||
appInfo->fastTransDataSize) != EOK) {
|
||||
TRANS_LOGE(TRANS_CTRL, "memcpy fastTransData fail");
|
||||
SoftBusFree(fastTransData);
|
||||
return SOFTBUS_MEM_ERR;
|
||||
}
|
||||
chan->appInfo.fastTransData = fastTransData;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t TransProxyCreateChanInfo(ProxyChannelInfo *chan, int32_t channelId, const AppInfo *appInfo)
|
||||
{
|
||||
chan->myId = (int16_t)channelId;
|
||||
@ -1485,7 +1510,14 @@ int32_t TransProxyCreateChanInfo(ProxyChannelInfo *chan, int32_t channelId, cons
|
||||
}
|
||||
}
|
||||
|
||||
(void)memcpy_s(&(chan->appInfo), sizeof(chan->appInfo), appInfo, sizeof(AppInfo));
|
||||
if (memcpy_s(&(chan->appInfo), sizeof(chan->appInfo), appInfo, sizeof(AppInfo)) != EOK) {
|
||||
TRANS_LOGE(TRANS_CTRL, "appInfo memcpy failed.");
|
||||
return SOFTBUS_MEM_ERR;
|
||||
}
|
||||
if (CopyAppInfoFastTransData(chan, appInfo) != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_CTRL, "copy appinfo fast trans data fail");
|
||||
return SOFTBUS_MEM_ERR;
|
||||
}
|
||||
if (TransProxyAddChanItem(chan) != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_CTRL, "trans proxy add channelId fail. channelId=%{public}d", channelId);
|
||||
return SOFTBUS_ERR;
|
||||
|
@ -321,6 +321,9 @@ void TransProxyPostOpenFailMsgToLoop(const ProxyChannelInfo *chan, int32_t errCo
|
||||
if (msg == NULL) {
|
||||
TRANS_LOGE(TRANS_MSG, "msg create failed");
|
||||
if (chan != NULL) {
|
||||
if (chan->appInfo.fastTransData != NULL) {
|
||||
SoftBusFree((void *)chan->appInfo.fastTransData);
|
||||
}
|
||||
SoftBusFree((void *)chan);
|
||||
}
|
||||
return;
|
||||
|
@ -855,8 +855,32 @@ static int32_t StartVerifyP2pInfo(const AppInfo *appInfo, SessionConn *conn)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t OpenP2pDirectChannel(const AppInfo *appInfo, const ConnectOption *connInfo,
|
||||
int32_t *channelId)
|
||||
static int32_t CopyAppInfoFastTransData(SessionConn *conn, const AppInfo *appInfo)
|
||||
{
|
||||
if (appInfo->fastTransData != NULL && appInfo->fastTransDataSize > 0) {
|
||||
uint8_t *fastTransData = (uint8_t *)SoftBusCalloc(appInfo->fastTransDataSize);
|
||||
if (fastTransData == NULL) {
|
||||
return SOFTBUS_MALLOC_ERR;
|
||||
}
|
||||
if (memcpy_s((char *)fastTransData, appInfo->fastTransDataSize, (const char *)appInfo->fastTransData,
|
||||
appInfo->fastTransDataSize) != EOK) {
|
||||
TRANS_LOGE(TRANS_CTRL, "memcpy fastTransData fail");
|
||||
SoftBusFree(fastTransData);
|
||||
return SOFTBUS_MEM_ERR;
|
||||
}
|
||||
conn->appInfo.fastTransData = fastTransData;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static void FreeFastTransData(AppInfo *appInfo)
|
||||
{
|
||||
if (appInfo != NULL && appInfo->fastTransData != NULL) {
|
||||
SoftBusFree((void *)(appInfo->fastTransData));
|
||||
}
|
||||
}
|
||||
|
||||
int32_t OpenP2pDirectChannel(const AppInfo *appInfo, const ConnectOption *connInfo, int32_t *channelId)
|
||||
{
|
||||
TRANS_LOGI(TRANS_CTRL, "enter.");
|
||||
if (appInfo == NULL || connInfo == NULL || channelId == NULL ||
|
||||
@ -875,14 +899,24 @@ int32_t OpenP2pDirectChannel(const AppInfo *appInfo, const ConnectOption *connIn
|
||||
SoftbusHitraceStart(SOFTBUS_HITRACE_ID_VALID, (uint64_t)(conn->channelId + ID_OFFSET));
|
||||
TRANS_LOGI(TRANS_CTRL,
|
||||
"SoftbusHitraceChainBegin: set HitraceId=%{public}" PRIu64, (uint64_t)(conn->channelId + ID_OFFSET));
|
||||
(void)memcpy_s(&conn->appInfo, sizeof(AppInfo), appInfo, sizeof(AppInfo));
|
||||
|
||||
if (memcpy_s(&conn->appInfo, sizeof(AppInfo), appInfo, sizeof(AppInfo)) != EOK) {
|
||||
TRANS_LOGE(TRANS_CTRL, "copy appInfo fail");
|
||||
SoftBusFree(conn);
|
||||
return SOFTBUS_MEM_ERR;
|
||||
}
|
||||
ret = CopyAppInfoFastTransData(conn, appInfo);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
SoftBusFree(conn);
|
||||
TRANS_LOGE(TRANS_CTRL, "copy appinfo fast trans data fail");
|
||||
return ret;
|
||||
}
|
||||
if (connInfo->type == CONNECT_P2P) {
|
||||
ret = StartP2pListener(conn->appInfo.myData.addr, &conn->appInfo.myData.port);
|
||||
} else {
|
||||
ret = StartHmlListener(conn->appInfo.myData.addr, &conn->appInfo.myData.port);
|
||||
}
|
||||
if (ret != SOFTBUS_OK) {
|
||||
FreeFastTransData(&(conn->appInfo));
|
||||
SoftBusFree(conn);
|
||||
TRANS_LOGE(TRANS_CTRL, "start listener fail");
|
||||
return ret;
|
||||
@ -890,6 +924,7 @@ int32_t OpenP2pDirectChannel(const AppInfo *appInfo, const ConnectOption *connIn
|
||||
|
||||
uint64_t seq = TransTdcGetNewSeqId();
|
||||
if (seq == INVALID_SEQ_ID) {
|
||||
FreeFastTransData(&(conn->appInfo));
|
||||
SoftBusFree(conn);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
@ -898,6 +933,7 @@ int32_t OpenP2pDirectChannel(const AppInfo *appInfo, const ConnectOption *connIn
|
||||
conn->isMeta = TransGetAuthTypeByNetWorkId(appInfo->peerNetWorkId);
|
||||
ret = TransTdcAddSessionConn(conn);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
FreeFastTransData(&(conn->appInfo));
|
||||
SoftBusFree(conn);
|
||||
return ret;
|
||||
}
|
||||
|
@ -292,6 +292,9 @@ void TransDelSessionConnById(int32_t channelId)
|
||||
}
|
||||
ListDelete(&item->node);
|
||||
TRANS_LOGI(TRANS_CTRL, "delete channelId=%{public}d", item->channelId);
|
||||
if (item->appInfo.fastTransData != NULL) {
|
||||
SoftBusFree((void*)item->appInfo.fastTransData);
|
||||
}
|
||||
SoftBusFree(item);
|
||||
g_sessionConnList->cnt--;
|
||||
ReleaseSessonConnLock();
|
||||
|
@ -33,10 +33,18 @@
|
||||
#define HML_IP_PREFIX "172.30."
|
||||
#define NETWORK_ID_LEN 7
|
||||
|
||||
static void FreeFastTransData(AppInfo *appInfo)
|
||||
{
|
||||
if (appInfo != NULL && appInfo->fastTransData != NULL) {
|
||||
SoftBusFree((void *)(appInfo->fastTransData));
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t AddTcpConnAndSessionInfo(int32_t newchannelId, int32_t fd, SessionConn *newConn,
|
||||
ListenerModule module)
|
||||
{
|
||||
if (TransSrvAddDataBufNode(newchannelId, fd) != SOFTBUS_OK) {
|
||||
FreeFastTransData(&(newConn->appInfo));
|
||||
SoftBusFree(newConn);
|
||||
TRANS_LOGE(TRANS_CTRL, "OpenTcpDirectChannel create databuf fail");
|
||||
return SOFTBUS_MALLOC_ERR;
|
||||
@ -44,6 +52,7 @@ static int32_t AddTcpConnAndSessionInfo(int32_t newchannelId, int32_t fd, Sessio
|
||||
|
||||
if (TransTdcAddSessionConn(newConn) != SOFTBUS_OK) {
|
||||
TransSrvDelDataBufNode(newchannelId);
|
||||
FreeFastTransData(&(newConn->appInfo));
|
||||
SoftBusFree(newConn);
|
||||
return SOFTBUS_TRANS_ADD_SESSION_CONN_FAILED;
|
||||
}
|
||||
@ -84,8 +93,25 @@ static ListenerModule GetMoudleType(ConnectType type, const char *peerIp)
|
||||
return module;
|
||||
}
|
||||
|
||||
int32_t OpenTcpDirectChannel(const AppInfo *appInfo, const ConnectOption *connInfo,
|
||||
int32_t *channelId)
|
||||
static int32_t CopyAppInfoFastTransData(SessionConn *conn, const AppInfo *appInfo)
|
||||
{
|
||||
if (appInfo->fastTransData != NULL && appInfo->fastTransDataSize > 0) {
|
||||
uint8_t *fastTransData = (uint8_t *)SoftBusCalloc(appInfo->fastTransDataSize);
|
||||
if (fastTransData == NULL) {
|
||||
return SOFTBUS_MALLOC_ERR;
|
||||
}
|
||||
if (memcpy_s((char *)fastTransData, appInfo->fastTransDataSize, (const char *)appInfo->fastTransData,
|
||||
appInfo->fastTransDataSize) != EOK) {
|
||||
SoftBusFree(fastTransData);
|
||||
TRANS_LOGE(TRANS_CTRL, "memcpy fastTransData fail");
|
||||
return SOFTBUS_MEM_ERR;
|
||||
}
|
||||
conn->appInfo.fastTransData = fastTransData;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t OpenTcpDirectChannel(const AppInfo *appInfo, const ConnectOption *connInfo, int32_t *channelId)
|
||||
{
|
||||
TRANS_LOGI(TRANS_CTRL, "enter.");
|
||||
if (appInfo == NULL || connInfo == NULL || channelId == NULL) {
|
||||
@ -109,14 +135,24 @@ int32_t OpenTcpDirectChannel(const AppInfo *appInfo, const ConnectOption *connIn
|
||||
TRANS_LOGI(TRANS_CTRL,
|
||||
"SoftbusHitraceChainBegin: set HitraceId=%{public}" PRIu64, (uint64_t)(newConn->channelId + ID_OFFSET));
|
||||
int32_t newchannelId = newConn->channelId;
|
||||
(void)memcpy_s(&newConn->appInfo, sizeof(AppInfo), appInfo, sizeof(AppInfo));
|
||||
|
||||
if (memcpy_s(&newConn->appInfo, sizeof(AppInfo), appInfo, sizeof(AppInfo)) != EOK) {
|
||||
TRANS_LOGE(TRANS_CTRL, "copy appInfo fail");
|
||||
SoftBusFree(newConn);
|
||||
return SOFTBUS_MEM_ERR;
|
||||
}
|
||||
int32_t ret = CopyAppInfoFastTransData(newConn, appInfo);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
SoftBusFree(newConn);
|
||||
TRANS_LOGE(TRANS_CTRL, "copy appinfo fast trans data fail");
|
||||
return ret;
|
||||
}
|
||||
AuthGetLatestIdByUuid(newConn->appInfo.peerData.deviceId, AUTH_LINK_TYPE_WIFI, false, &newConn->authHandle);
|
||||
if ((newConn->authHandle.authId == AUTH_INVALID_ID) && (connInfo->type == CONNECT_P2P_REUSE)) {
|
||||
AuthGetLatestIdByUuid(newConn->appInfo.peerData.deviceId, AUTH_LINK_TYPE_BR, false, &newConn->authHandle);
|
||||
}
|
||||
|
||||
if (newConn->authHandle.authId == AUTH_INVALID_ID) {
|
||||
FreeFastTransData(&(newConn->appInfo));
|
||||
SoftBusFree(newConn);
|
||||
TRANS_LOGE(TRANS_CTRL, "get authId fail");
|
||||
return SOFTBUS_TRANS_TCP_GET_AUTHID_FAILED;
|
||||
@ -124,13 +160,14 @@ int32_t OpenTcpDirectChannel(const AppInfo *appInfo, const ConnectOption *connIn
|
||||
|
||||
int32_t fd = ConnOpenClientSocket(connInfo, BIND_ADDR_ALL, true);
|
||||
if (fd < 0) {
|
||||
FreeFastTransData(&(newConn->appInfo));
|
||||
SoftBusFree(newConn);
|
||||
TRANS_LOGE(TRANS_CTRL, "connect fail");
|
||||
return fd;
|
||||
}
|
||||
newConn->appInfo.fd = fd;
|
||||
|
||||
int32_t ret = AddTcpConnAndSessionInfo(newchannelId, fd, newConn, module);
|
||||
ret = AddTcpConnAndSessionInfo(newchannelId, fd, newConn, module);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
@ -197,6 +197,9 @@ int32_t TransDelUdpChannel(int32_t channelId)
|
||||
ReleaseUdpChannelId((int32_t)(udpChannelNode->info.myData.channelId));
|
||||
ListDelete(&(udpChannelNode->node));
|
||||
TRANS_LOGI(TRANS_CTRL, "delete channelId=%{public}d", channelId);
|
||||
if (udpChannelNode->info.fastTransData != NULL) {
|
||||
SoftBusFree((void *)(udpChannelNode->info.fastTransData));
|
||||
}
|
||||
SoftBusFree(udpChannelNode);
|
||||
g_udpChannelMgr->cnt--;
|
||||
(void)SoftBusMutexUnlock(&(g_udpChannelMgr->lock));
|
||||
@ -217,6 +220,9 @@ static void NotifyUdpChannelCloseInList(ListNode *udpChannelList)
|
||||
|
||||
ListDelete(&(udpChannel->node));
|
||||
TRANS_LOGI(TRANS_CTRL, "channelId=%{public}" PRId64, udpChannel->info.myData.channelId);
|
||||
if (udpChannel->info.fastTransData != NULL) {
|
||||
SoftBusFree((void *)(udpChannel->info.fastTransData));
|
||||
}
|
||||
SoftBusFree(udpChannel);
|
||||
}
|
||||
}
|
||||
|
@ -239,6 +239,24 @@ int32_t NotifyUdpQosEvent(const AppInfo *info, int32_t eventId, int32_t tvCount,
|
||||
return g_channelCb->OnQosEvent(pkgName, ¶m);
|
||||
}
|
||||
|
||||
static int32_t CopyAppInfoFastTransData(UdpChannelInfo *newChannel, const AppInfo *appInfo)
|
||||
{
|
||||
if (appInfo->fastTransData != NULL && appInfo->fastTransDataSize > 0) {
|
||||
uint8_t *fastTransData = (uint8_t *)SoftBusCalloc(appInfo->fastTransDataSize);
|
||||
if (fastTransData == NULL) {
|
||||
return SOFTBUS_MALLOC_ERR;
|
||||
}
|
||||
if (memcpy_s((char *)fastTransData, appInfo->fastTransDataSize, (const char *)appInfo->fastTransData,
|
||||
appInfo->fastTransDataSize) != EOK) {
|
||||
TRANS_LOGE(TRANS_CTRL, "memcpy fastTransData fail");
|
||||
SoftBusFree(fastTransData);
|
||||
return SOFTBUS_MEM_ERR;
|
||||
}
|
||||
newChannel->info.fastTransData = fastTransData;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static UdpChannelInfo *NewUdpChannelByAppInfo(const AppInfo *info)
|
||||
{
|
||||
UdpChannelInfo *newChannel = (UdpChannelInfo *)SoftBusCalloc(sizeof(UdpChannelInfo));
|
||||
@ -252,6 +270,11 @@ static UdpChannelInfo *NewUdpChannelByAppInfo(const AppInfo *info)
|
||||
SoftBusFree(newChannel);
|
||||
return NULL;
|
||||
}
|
||||
if (CopyAppInfoFastTransData(newChannel, info) != SOFTBUS_OK) {
|
||||
SoftBusFree(newChannel);
|
||||
TRANS_LOGE(TRANS_CTRL, "copy appinfo fast trans data fail");
|
||||
return NULL;
|
||||
}
|
||||
return newChannel;
|
||||
}
|
||||
|
||||
|
@ -512,13 +512,13 @@ HWTEST_F(TransLaneTest, TransLaneTest013, TestSize.Level1)
|
||||
|
||||
(void)memcpy_s(&requestOption.requestInfo, sizeof(TransOption), &trans, sizeof(TransOption));
|
||||
ret = TransAddLaneReqToPendingAndWaiting(laneHandle, NULL);
|
||||
EXPECT_EQ(SOFTBUS_ERR, ret);
|
||||
EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
|
||||
|
||||
ret = TransAddLaneReqToPendingAndWaiting(laneHandle, &requestOption);
|
||||
EXPECT_EQ(SOFTBUS_ERR, ret);
|
||||
EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
|
||||
|
||||
ret = TransAddLaneReqToPendingAndWaiting(laneHandle, &requestOption);
|
||||
EXPECT_EQ(SOFTBUS_ERR, ret);
|
||||
EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
|
||||
|
||||
(void)TransDelLaneReqFromPendingList(laneHandle, false);
|
||||
LnnDeinitDistributedLedger();
|
||||
|
Loading…
Reference in New Issue
Block a user