diff --git a/services/codec/src/audio_aac_codec.cpp b/services/codec/src/audio_aac_codec.cpp index 2156a49ed422de905dc57b119c30dc7dd6b4799d..2db7a40f2a18b910a3bcc811a81dda008dd995af 100755 --- a/services/codec/src/audio_aac_codec.cpp +++ b/services/codec/src/audio_aac_codec.cpp @@ -262,6 +262,7 @@ int32_t AudioAACEncoder::Init(uint32_t channels, uint32_t sampleBit, uint32_t sa encFrame_ = av_frame_alloc(); if (!encFrame_) { SHARING_LOGE("Could not allocate audio encode in frame"); + return 1; } encFrame_->format = enc_->sample_fmt; encFrame_->nb_samples = enc_->frame_size; diff --git a/services/mediachannel/buffer_dispatcher.cpp b/services/mediachannel/buffer_dispatcher.cpp index 84a9131a5d64ef6c114de948730dbc7eeacb659f..91970eadec715b4667c9043bebd1c0b03718ec00 100755 --- a/services/mediachannel/buffer_dispatcher.cpp +++ b/services/mediachannel/buffer_dispatcher.cpp @@ -506,14 +506,14 @@ void BufferDispatcher::ReleaseIdleBuffer() SHARING_LOGD("BufferDispatcher idle Release Start."); std::unique_lock locker(idleMutex_); for (auto &data : idleAudioBuffer_) { - if (data != nullptr || data->buff != nullptr) { + if (data != nullptr && data->buff != nullptr) { data->buff.reset(); } } idleAudioBuffer_.clear(); for (auto &data : idleVideoBuffer_) { - if (data != nullptr || data->buff != nullptr) { + if (data != nullptr && data->buff != nullptr) { data->buff.reset(); } } diff --git a/services/mediaplayer/src/audio_play_controller.cpp b/services/mediaplayer/src/audio_play_controller.cpp index cfa3558a9b1ade5949a2ca6f077cc5c2a5909c3e..75e7f0b3de1b3cbbd46842bf33b5078696e1ae3a 100755 --- a/services/mediaplayer/src/audio_play_controller.cpp +++ b/services/mediaplayer/src/audio_play_controller.cpp @@ -115,11 +115,12 @@ void AudioPlayController::StartAudioThread() } audioPlayThread_ = std::make_shared(&AudioPlayController::AudioPlayThread, this); - std::string name = "audioplay"; - pthread_setname_np(audioPlayThread_->native_handle(), name.c_str()); if (audioPlayThread_ == nullptr) { SHARING_LOGE("play start create thread error, mediachannelId: %{public}u!", mediachannelId_); + return; } + std::string name = "audioplay"; + pthread_setname_np(audioPlayThread_->native_handle(), name.c_str()); } void AudioPlayController::StopAudioThread() diff --git a/services/mediaplayer/src/video_play_controller.cpp b/services/mediaplayer/src/video_play_controller.cpp index 47191b53c473af4cdb544526e45dab421c4a1543..6ef70624a43cfa5965b63a4b8af0a698980f067d 100755 --- a/services/mediaplayer/src/video_play_controller.cpp +++ b/services/mediaplayer/src/video_play_controller.cpp @@ -179,11 +179,12 @@ void VideoPlayController::StartVideoThread() } videoPlayThread_ = std::make_shared(&VideoPlayController::VideoPlayThread, this); - std::string name = "videoplay"; - pthread_setname_np(videoPlayThread_->native_handle(), name.c_str()); if (videoPlayThread_ == nullptr) { SHARING_LOGE("play start create thread error, mediachannelId: %{public}u!", mediachannelId_); + return; } + std::string name = "videoplay"; + pthread_setname_np(videoPlayThread_->native_handle(), name.c_str()); } void VideoPlayController::StopVideoThread() diff --git a/services/network/client/tcp_client.cpp b/services/network/client/tcp_client.cpp index 842edf2fee6b5654359a90da15d94dd83344517b..496420c576357e231cbf2c55382ce1399f9070d9 100755 --- a/services/network/client/tcp_client.cpp +++ b/services/network/client/tcp_client.cpp @@ -49,10 +49,12 @@ bool TcpClient::Connect(const std::string &peerIp, uint16_t peerPort, const std: eventHandler_->SetEventRunner(eventRunner); eventRunner->Run(); + bool ret = false; eventListener_ = std::make_shared(); - eventListener_->SetClient(shared_from_this()); - - bool ret = eventListener_->AddFdListener(socket_->GetLocalFd(), eventListener_, eventHandler_); + if (eventListener_) { + eventListener_->SetClient(shared_from_this()); + ret = eventListener_->AddFdListener(socket_->GetLocalFd(), eventListener_, eventHandler_); + } auto callback = callback_.lock(); if (callback) { diff --git a/services/network/server/udp_server.cpp b/services/network/server/udp_server.cpp index 90245fc9f23acf086fb3f62bfaa2f7a56efcff2a..438b9628825a9ea157bbb75f4ffce5fe019cc36f 100755 --- a/services/network/server/udp_server.cpp +++ b/services/network/server/udp_server.cpp @@ -205,6 +205,10 @@ std::shared_ptr UdpServer::FindOrCreateSession(const struct SocketInfo::Ptr socketInfo = std::make_shared(socket_->GetLocalIp(), inet_ntoa(addr.sin_addr), socket_->GetLocalFd(), peerFd, socket_->GetLocalPort(), addr.sin_port); + if (socketInfo == nullptr) { + SHARING_LOGE("create socket info failed!"); + return nullptr; + } auto ret = memcpy_s(&socketInfo->udpClientAddr_, sizeof(struct sockaddr_in), &addr, sizeof(struct sockaddr_in)); if (ret != EOK) { MEDIA_LOGE("mem copy data failed."); @@ -212,24 +216,22 @@ std::shared_ptr UdpServer::FindOrCreateSession(const struct } socketInfo->SetSocketType(SOCKET_TYPE_UDP); - if (socketInfo) { - BaseNetworkSession::Ptr session = std::make_shared(std::move(socketInfo)); - if (session) { - auto peerAddr = std::make_shared(); - auto ret = memcpy_s(peerAddr.get(), sizeof(struct sockaddr_in), &addr, sizeof(struct sockaddr_in)); - if (ret != EOK) { - MEDIA_LOGE("mem copy data failed."); - return nullptr; - } - addrToFdMap_.insert(make_pair(peerAddr, peerFd)); - sessionMap_.insert(make_pair(peerFd, std::move(session))); - auto callback = callback_.lock(); - if (callback) { - callback->OnAccept(sessionMap_[peerFd]); - } - - return sessionMap_[peerFd]; + BaseNetworkSession::Ptr session = std::make_shared(std::move(socketInfo)); + if (session) { + auto peerAddr = std::make_shared(); + auto ret = memcpy_s(peerAddr.get(), sizeof(struct sockaddr_in), &addr, sizeof(struct sockaddr_in)); + if (ret != EOK) { + MEDIA_LOGE("mem copy data failed."); + return nullptr; } + addrToFdMap_.insert(make_pair(peerAddr, peerFd)); + sessionMap_.insert(make_pair(peerFd, std::move(session))); + auto callback = callback_.lock(); + if (callback) { + callback->OnAccept(sessionMap_[peerFd]); + } + + return sessionMap_[peerFd]; } } diff --git a/services/network/session/udp_session.cpp b/services/network/session/udp_session.cpp index cf8c967b3980e33d2a7b4e80b907b9afe0b947ba..dd804f8fc5523cdfe986fbd7a26a993466aa368e 100755 --- a/services/network/session/udp_session.cpp +++ b/services/network/session/udp_session.cpp @@ -100,12 +100,13 @@ bool UdpSession::Send(const char *buf, int32_t nSize) void UdpSession::OnSessionReadble(int32_t fd) { - SHARING_LOGD("fd: %{public}d, local_fd:%{public}d, thread_id: %{public}llu.", fd, socket_->GetLocalFd(), - GetThreadId()); if (socket_ == nullptr) { MEDIA_LOGE("socket nullptr!"); return; } + SHARING_LOGD("fd: %{public}d, local_fd:%{public}d, thread_id: %{public}llu.", fd, socket_->GetLocalFd(), + GetThreadId()); + if (fd == socket_->GetLocalFd()) { int32_t retCode = 0; do { diff --git a/tests/demo/interaction/wfd_sink_demo.cpp b/tests/demo/interaction/wfd_sink_demo.cpp index 0dcf0ccb592e6c973181d21e0ed4466f52d43f5d..f5ce2db54472d43c4ce03491668ddc53ad3a6010 100644 --- a/tests/demo/interaction/wfd_sink_demo.cpp +++ b/tests/demo/interaction/wfd_sink_demo.cpp @@ -67,7 +67,7 @@ bool WfdSinkDemo::CreateClient() bool WfdSinkDemo::SetDiscoverable(bool enable) { - if (!client_) { + if (client_) { int ret = 0; if (enable) { ret = client_->Start(); @@ -436,6 +436,7 @@ void WfdSinkDemoListener::OnConnectionChanged(const ConnectionInfo &info) auto listener = listener_.lock(); if (!listener) { printf("no listener"); + return; } switch (info.state) { case ConnectionState::CONNECTED: { diff --git a/tests/demo/interaction/wfd_source_demo.cpp b/tests/demo/interaction/wfd_source_demo.cpp index a0ddd57263e4e89948184be97364b511aab88133..3976eb3a4fbbb72d46a0a4a04f9e43b91770fb05 100644 --- a/tests/demo/interaction/wfd_source_demo.cpp +++ b/tests/demo/interaction/wfd_source_demo.cpp @@ -214,6 +214,7 @@ void WfdSourceDemoListener::OnInfo(std::shared_ptr &msg) auto listener = listener_.lock(); if (!listener) { printf("no listener.\n"); + break; } listener->RemoveCastDevice(g_deviceId); break;