Skip to content

Commit 0534e10

Browse files
trupthi1403tboova469_comcast
authored andcommitted
Coverity- High priority issue fixes
Summary: Fix for lock, missing_lock, uninitialized fields and uncaught exception Type: Fix Test Plan: UT/CT, Fullstack Jira: RDKEMW-17892
1 parent fb468d9 commit 0534e10

10 files changed

Lines changed: 138 additions & 99 deletions

File tree

common/source/LinuxUtils.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "LinuxUtils.h"
2121
#include "RialtoCommonLogging.h"
22+
#include <cstdint>
2223
#include <grp.h>
2324
#include <pwd.h>
2425
#include <sys/stat.h>
@@ -32,8 +33,8 @@ constexpr gid_t kNoGroupChange = -1; // -1 means chown() won't change the group
3233
uid_t getFileOwnerId(const std::string &fileOwner)
3334
{
3435
uid_t ownerId = kNoOwnerChange;
35-
// sysconf returns long; -1 on error. Store as long to avoid unsigned conversion issues.
36-
const long bufferSizeLong = sysconf(_SC_GETPW_R_SIZE_MAX);
36+
// sysconf returns long; -1 on error. Store as int64_t to avoid unsigned conversion issues.
37+
const int64_t bufferSizeLong = sysconf(_SC_GETPW_R_SIZE_MAX);
3738
if (!fileOwner.empty() && bufferSizeLong > 0)
3839
{
3940
const size_t kBufferSize = static_cast<size_t>(bufferSizeLong);
@@ -57,8 +58,8 @@ uid_t getFileOwnerId(const std::string &fileOwner)
5758
gid_t getFileGroupId(const std::string &fileGroup)
5859
{
5960
gid_t groupId = kNoGroupChange;
60-
// sysconf returns long; -1 on error. Store as long to avoid unsigned conversion issues.
61-
const long bufferSizeLong = sysconf(_SC_GETPW_R_SIZE_MAX);
61+
// sysconf returns long; -1 on error. Store as int64_t to avoid unsigned conversion issues.
62+
const int64_t bufferSizeLong = sysconf(_SC_GETGR_R_SIZE_MAX);
6263
if (!fileGroup.empty() && bufferSizeLong > 0)
6364
{
6465
const size_t kBufferSize = static_cast<size_t>(bufferSizeLong);

ipc/client/source/IpcChannelImpl.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -765,26 +765,27 @@ void ChannelImpl::processErrorFromServer(const transport::MethodCallError &error
765765
{
766766
RIALTO_IPC_LOG_DEBUG("processing error from server");
767767

768-
std::unique_lock<std::mutex> locker(m_lock);
769-
770-
// find the original request
768+
MethodCall methodCall;
771769
const uint64_t kSerialId = error.reply_id();
772-
auto it = m_methodCalls.find(kSerialId);
773-
if (it == m_methodCalls.end())
770+
774771
{
775-
RIALTO_IPC_LOG_ERROR("failed to find request for received reply with id %" PRIu64 "", error.reply_id());
776-
return;
777-
}
772+
std::unique_lock<std::mutex> locker(m_lock);
778773

779-
// take the method call and remove from the map of outstanding calls
780-
MethodCall methodCall = it->second;
781-
m_methodCalls.erase(it);
774+
// find the original request
775+
auto it = m_methodCalls.find(kSerialId);
776+
if (it == m_methodCalls.end())
777+
{
778+
RIALTO_IPC_LOG_ERROR("failed to find request for received reply with id %" PRIu64 "", error.reply_id());
779+
return;
780+
}
782781

783-
// update the timeout timer now a method call has been processed
784-
updateTimeoutTimer();
782+
// take the method call and remove from the map of outstanding calls
783+
methodCall = it->second;
784+
m_methodCalls.erase(it);
785785

786-
// can now drop the lock
787-
locker.unlock();
786+
// update the timeout timer now a method call has been processed
787+
updateTimeoutTimer();
788+
}
788789

789790
RIALTO_IPC_LOG_DEBUG("error{ serial %" PRIu64 " } - %s", kSerialId, error.error_reason().c_str());
790791

ipc/common/source/NamedSocket.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "NamedSocket.h"
2121
#include "IpcLogging.h"
22+
#include <cstdint>
2223
#include <grp.h>
2324
#include <pwd.h>
2425
#include <stdexcept>
@@ -268,8 +269,8 @@ bool NamedSocket::getSocketLock()
268269
uid_t NamedSocket::getSocketOwnerId(const std::string &socketOwner) const
269270
{
270271
uid_t ownerId = kNoOwnerChange;
271-
// sysconf returns long; -1 on error. Store as long to avoid unsigned conversion issues.
272-
const long bufferSizeLong = sysconf(_SC_GETPW_R_SIZE_MAX);
272+
// sysconf returns long; -1 on error. Store as int64_t to avoid unsigned conversion issues.
273+
const int64_t bufferSizeLong = sysconf(_SC_GETPW_R_SIZE_MAX);
273274
if (!socketOwner.empty() && bufferSizeLong > 0)
274275
{
275276
const size_t kBufferSize = static_cast<size_t>(bufferSizeLong);
@@ -293,8 +294,8 @@ uid_t NamedSocket::getSocketOwnerId(const std::string &socketOwner) const
293294
gid_t NamedSocket::getSocketGroupId(const std::string &socketGroup) const
294295
{
295296
gid_t groupId = kNoGroupChange;
296-
// sysconf returns long; -1 on error. Store as long to avoid unsigned conversion issues.
297-
const long bufferSizeLong = sysconf(_SC_GETPW_R_SIZE_MAX);
297+
// sysconf returns long; -1 on error. Store as int64_t to avoid unsigned conversion issues.
298+
const int64_t bufferSizeLong = sysconf(_SC_GETGR_R_SIZE_MAX);
298299
if (!socketGroup.empty() && bufferSizeLong > 0)
299300
{
300301
const size_t kBufferSize = static_cast<size_t>(bufferSizeLong);

ipc/server/source/IpcServerImpl.cpp

Lines changed: 64 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -616,37 +616,42 @@ void ServerImpl::processNewConnection(uint64_t socketId)
616616
{
617617
RIALTO_IPC_LOG_DEBUG("processing new connection");
618618

619-
std::unique_lock<std::mutex> socketLocker(m_socketsLock);
619+
int clientSock;
620+
std::string sockPath;
621+
std::function<void(const std::shared_ptr<IClient> &)> connectedCb;
622+
std::function<void(const std::shared_ptr<IClient> &)> disconnectedCb;
620623

621-
// find matching socket object
622-
auto it = m_sockets.find(socketId);
623-
if (it == m_sockets.end())
624624
{
625-
RIALTO_IPC_LOG_ERROR("failed to find listening socket with id %" PRIu64, socketId);
626-
return;
627-
}
625+
std::unique_lock<std::mutex> socketLocker(m_socketsLock);
628626

629-
const Socket &kSocket = it->second;
627+
// find matching socket object
628+
auto it = m_sockets.find(socketId);
629+
if (it == m_sockets.end())
630+
{
631+
RIALTO_IPC_LOG_ERROR("failed to find listening socket with id %" PRIu64, socketId);
632+
return;
633+
}
630634

631-
// accept the connection from the client
632-
struct sockaddr clientAddr = {0};
633-
socklen_t clientAddrLen = sizeof(clientAddr);
635+
const Socket &kSocket = it->second;
634636

635-
int clientSock = accept4(kSocket.sockFd, &clientAddr, &clientAddrLen, SOCK_NONBLOCK | SOCK_CLOEXEC);
636-
if (clientSock < 0)
637-
{
638-
RIALTO_IPC_LOG_SYS_ERROR(errno, "failed to accept client connection");
639-
return;
640-
}
637+
// accept the connection from the client
638+
struct sockaddr clientAddr = {0};
639+
socklen_t clientAddrLen = sizeof(clientAddr);
641640

642-
const std::string kSockPath = kSocket.sockPath;
643-
std::function<void(const std::shared_ptr<IClient> &)> connectedCb = kSocket.connectedCb;
644-
std::function<void(const std::shared_ptr<IClient> &)> disconnectedCb = kSocket.disconnectedCb;
641+
clientSock = accept4(kSocket.sockFd, &clientAddr, &clientAddrLen, SOCK_NONBLOCK | SOCK_CLOEXEC);
642+
if (clientSock < 0)
643+
{
644+
RIALTO_IPC_LOG_SYS_ERROR(errno, "failed to accept client connection");
645+
return;
646+
}
645647

646-
socketLocker.unlock();
648+
sockPath = kSocket.sockPath;
649+
connectedCb = kSocket.connectedCb;
650+
disconnectedCb = kSocket.disconnectedCb;
651+
}
647652

648653
// attempt to add the socket to the client list
649-
auto client = addClientSocket(clientSock, kSockPath, std::move(disconnectedCb));
654+
auto client = addClientSocket(clientSock, sockPath, std::move(disconnectedCb));
650655
if (!client)
651656
{
652657
close(clientSock);
@@ -736,31 +741,34 @@ static std::vector<FileDescriptor> readMessageFds(const struct msghdr *msg, size
736741
*/
737742
void ServerImpl::processClientSocket(uint64_t clientId, unsigned events)
738743
{
739-
// take the lock while accessing the client list
740-
std::unique_lock<std::mutex> locker(m_clientsLock);
744+
int sockFd;
745+
std::shared_ptr<ClientImpl> clientObj;
741746

742-
auto it = m_clients.find(clientId);
743-
if (it == m_clients.end())
747+
// take the lock while accessing the client list
744748
{
745-
// should never happen
746-
RIALTO_IPC_LOG_ERROR("received an event from a socket with no matching client");
747-
return;
748-
}
749+
std::unique_lock<std::mutex> locker(m_clientsLock);
749750

750-
// check if the client is marked for closure, if so then just ignore the data
751-
if (m_condemnedClients.count(clientId) != 0)
752-
{
753-
return;
754-
}
751+
auto it = m_clients.find(clientId);
752+
if (it == m_clients.end())
753+
{
754+
// should never happen
755+
RIALTO_IPC_LOG_ERROR("received an event from a socket with no matching client");
756+
return;
757+
}
755758

756-
// get the socket that corresponds to the client connection
757-
const int kSockFd = it->second.sock;
759+
// check if the client is marked for closure, if so then just ignore the data
760+
if (m_condemnedClients.count(clientId) != 0)
761+
{
762+
return;
763+
}
758764

759-
// get the client object
760-
std::shared_ptr<ClientImpl> clientObj = it->second.client;
765+
// get the socket that corresponds to the client connection
766+
sockFd = it->second.sock;
761767

762-
// can safely release the lock now we have the clientId and client object
763-
locker.unlock();
768+
// get the client object
769+
clientObj = it->second.client;
770+
}
771+
// lock is released here automatically
764772

765773
// if there was an error disconnect the socket
766774
if (events & EPOLLERR)
@@ -786,7 +794,7 @@ void ServerImpl::processClientSocket(uint64_t clientId, unsigned events)
786794
msg.msg_controllen = sizeof(m_recvCtrlBuf);
787795

788796
// read one message
789-
ssize_t rd = TEMP_FAILURE_RETRY(recvmsg(kSockFd, &msg, MSG_CMSG_CLOEXEC));
797+
ssize_t rd = TEMP_FAILURE_RETRY(recvmsg(sockFd, &msg, MSG_CMSG_CLOEXEC));
790798
if (rd < 0)
791799
{
792800
if (errno != EWOULDBLOCK)
@@ -1394,21 +1402,22 @@ bool ServerImpl::sendEvent(uint64_t clientId, const std::shared_ptr<google::prot
13941402
}
13951403

13961404
// finally, take the lock (so the socket is not closed beneath us) and send the reply
1397-
std::unique_lock<std::mutex> locker(m_clientsLock);
1398-
1399-
auto it = m_clients.find(clientId);
1400-
if (it == m_clients.end() || it->second.sock < 0)
1401-
{
1402-
RIALTO_IPC_LOG_WARN("socket closed before event could be sent");
1403-
return false;
1404-
}
1405-
else if (TEMP_FAILURE_RETRY(sendmsg(it->second.sock, header, MSG_NOSIGNAL)) != static_cast<ssize_t>(requiredDataLen))
14061405
{
1407-
RIALTO_IPC_LOG_SYS_ERROR(errno, "failed to send the complete event message");
1408-
return false;
1409-
}
1406+
std::unique_lock<std::mutex> locker(m_clientsLock);
14101407

1411-
locker.unlock();
1408+
auto it = m_clients.find(clientId);
1409+
if (it == m_clients.end() || it->second.sock < 0)
1410+
{
1411+
RIALTO_IPC_LOG_WARN("socket closed before event could be sent");
1412+
return false;
1413+
}
1414+
else if (TEMP_FAILURE_RETRY(sendmsg(it->second.sock, header, MSG_NOSIGNAL)) !=
1415+
static_cast<ssize_t>(requiredDataLen))
1416+
{
1417+
RIALTO_IPC_LOG_SYS_ERROR(errno, "failed to send the complete event message");
1418+
return false;
1419+
}
1420+
}
14121421

14131422
RIALTO_IPC_LOG_DEBUG("event{ %s } - { %s }", eventMessage->GetTypeName().c_str(),
14141423
eventMessage->ShortDebugString().c_str());

media/client/main/source/MediaPipeline.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ MediaPipeline::MediaPipeline(std::weak_ptr<IMediaPipelineClient> client, const V
184184
const std::shared_ptr<common::IMediaFrameWriterFactory> &mediaFrameWriterFactory,
185185
IClientController &clientController)
186186
: m_mediaPipelineClient(client), m_clientController{clientController}, m_currentAppState{ApplicationState::UNKNOWN},
187-
m_mediaFrameWriterFactory(mediaFrameWriterFactory), m_currentState(State::IDLE)
187+
m_mediaFrameWriterFactory(mediaFrameWriterFactory), m_currentState(State::IDLE), m_attachingSource(false)
188188
{
189189
RIALTO_CLIENT_LOG_DEBUG("entry:");
190190

@@ -545,28 +545,29 @@ bool MediaPipeline::flush(int32_t sourceId, bool resetTime, bool &async)
545545
{
546546
RIALTO_CLIENT_LOG_DEBUG("entry:");
547547

548-
std::unique_lock<std::mutex> flushLock{m_flushMutex};
549-
if (m_mediaPipelineIpc->flush(sourceId, resetTime, async))
550548
{
549+
std::unique_lock<std::mutex> flushLock{m_flushMutex};
550+
if (!m_mediaPipelineIpc->flush(sourceId, resetTime, async))
551+
{
552+
return false;
553+
}
551554
m_attachedSources.setFlushing(sourceId, true);
552-
flushLock.unlock();
555+
}
553556

554-
// Clear all need datas for flushed source
555-
std::lock_guard<std::mutex> lock{m_needDataRequestMapMutex};
556-
for (auto it = m_needDataRequestMap.begin(); it != m_needDataRequestMap.end();)
557+
// Clear all need datas for flushed source
558+
std::lock_guard<std::mutex> lock{m_needDataRequestMapMutex};
559+
for (auto it = m_needDataRequestMap.begin(); it != m_needDataRequestMap.end();)
560+
{
561+
if (it->second->sourceId == sourceId)
557562
{
558-
if (it->second->sourceId == sourceId)
559-
{
560-
it = m_needDataRequestMap.erase(it);
561-
}
562-
else
563-
{
564-
++it;
565-
}
563+
it = m_needDataRequestMap.erase(it);
564+
}
565+
else
566+
{
567+
++it;
566568
}
567-
return true;
568569
}
569-
return false;
570+
return true;
570571
}
571572

572573
bool MediaPipeline::setSourcePosition(int32_t sourceId, int64_t position, bool resetTime, double appliedRate,

media/server/gstplayer/source/GstDecryptor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ GstRialtoDecryptorPrivate::GstRialtoDecryptorPrivate(
233233
GstBaseTransform *parentElement,
234234
const std::shared_ptr<firebolt::rialto::wrappers::IGstWrapperFactory> &gstWrapperFactory,
235235
const std::shared_ptr<firebolt::rialto::wrappers::IGlibWrapperFactory> &glibWrapperFactory)
236-
: m_decryptorElement(parentElement)
236+
: m_decryptorElement(parentElement), m_decryptionService(nullptr)
237237
{
238238
if ((!gstWrapperFactory) || (!(m_gstWrapper = gstWrapperFactory->getGstWrapper())))
239239
{

media/server/gstplayer/source/GstGenericPlayer.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,31 @@ GstGenericPlayer::~GstGenericPlayer()
223223
RIALTO_SERVER_LOG_DEBUG("GstGenericPlayer is destructed.");
224224
m_gstDispatcherThread.reset();
225225

226-
resetWorkerThread();
226+
try
227+
{
228+
resetWorkerThread();
229+
}
230+
catch (const std::exception &e)
231+
{
232+
RIALTO_SERVER_LOG_ERROR("Exception during resetWorkerThread in destructor: %s", e.what());
233+
}
234+
catch (...)
235+
{
236+
RIALTO_SERVER_LOG_ERROR("Unknown exception during resetWorkerThread in destructor");
237+
}
227238

228-
termPipeline();
239+
try
240+
{
241+
termPipeline();
242+
}
243+
catch (const std::exception &e)
244+
{
245+
RIALTO_SERVER_LOG_ERROR("Exception during termPipeline in destructor: %s", e.what());
246+
}
247+
catch (...)
248+
{
249+
RIALTO_SERVER_LOG_ERROR("Unknown exception during termPipeline in destructor");
250+
}
229251
}
230252

231253
void GstGenericPlayer::initMsePipeline()

media/server/gstplayer/source/GstSrc.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ static void gstRialtoSrcFinalize(GObject *object)
4848
{
4949
GstRialtoSrc *src = GST_RIALTO_SRC(object);
5050
GstRialtoSrcPrivate *priv = src->priv;
51+
GST_OBJECT_LOCK(src);
5152
g_free(priv->uri);
53+
GST_OBJECT_UNLOCK(src);
5254
priv->~GstRialtoSrcPrivate();
5355
GST_CALL_PARENT(G_OBJECT_CLASS, finalize, (object));
5456
}

media/server/main/source/ActiveRequests.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ AddSegmentStatus ActiveRequests::addSegment(std::uint32_t requestId,
116116
return AddSegmentStatus::ERROR;
117117
}
118118

119+
std::unique_lock<std::mutex> lock{m_mutex};
119120
auto requestIter{m_requestMap.find(requestId)};
120121
if (requestIter != m_requestMap.end())
121122
{
@@ -127,6 +128,7 @@ AddSegmentStatus ActiveRequests::addSegment(std::uint32_t requestId,
127128

128129
const IMediaPipeline::MediaSegmentVector &ActiveRequests::getSegments(std::uint32_t requestId) const
129130
{
131+
std::unique_lock<std::mutex> lock{m_mutex};
130132
auto requestIter{m_requestMap.find(requestId)};
131133
if (requestIter != m_requestMap.end())
132134
{

media/server/main/source/NeedMediaData.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ NeedMediaData::NeedMediaData(std::weak_ptr<IMediaPipelineClient> client, IActive
3131
const ISharedMemoryBuffer &shmBuffer, int sessionId, MediaSourceType mediaSourceType,
3232
std::int32_t sourceId, PlaybackState currentPlaybackState)
3333
: m_client{client}, m_activeRequests{activeRequests}, m_mediaSourceType{mediaSourceType}, m_frameCount{kMaxFrames},
34-
m_sourceId{sourceId}
34+
m_sourceId{sourceId}, m_maxMediaBytes{0}
3535
{
3636
if (PlaybackState::PLAYING != currentPlaybackState)
3737
{

0 commit comments

Comments
 (0)