Skip to content
This repository was archived by the owner on Jan 26, 2023. It is now read-only.
/ rdk-aamp Public archive

Commit b94e69c

Browse files
Vinish K BPaulpandian Mariappan
Vinish K B
authored and
Paulpandian Mariappan
committed
RDKAAMP-427 [AAMP] Fix possible thread leak in AAMP
Reason for change: Fix for original issue DELIA-58622 Fix thread management in AAMP Test Procedure: Play various assets in AAMP and make sure there is no thread leak Can be monitored by dumping /proc/<pid>/status Risks: Low Signed-off-by: Vinish K B <[email protected]> Change-Id: I85ec278b8b7b81248ed2962aa3b90433947c469e (cherry picked from commit 592a042)
1 parent 1f0fec0 commit b94e69c

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

AampCacheHandler.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ void AampCacheHandler::Init()
236236
//Check if already initialized
237237
if(true == mInitialized)
238238
return;
239-
240239
if(0 != pthread_create(&mAsyncCleanUpTaskThreadId, NULL, &AampCacheThreadFunction, this))
241240
{
242241
AAMPLOG_ERR("Failed to create AampCacheHandler thread errno = %d, %s", errno, strerror(errno));
@@ -273,6 +272,7 @@ void AampCacheHandler::ClearCacheHandler()
273272
{
274273
AAMPLOG_ERR("***pthread_join AsyncCacheCleanUpTask returned %d(%s)", rc, strerror(rc));
275274
}
275+
mAsyncThreadStartedFlag = false;
276276
}
277277
ClearPlaylistCache();
278278

admanager_mpd.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void CDAIObjectMPD::SetAlternateContents(const std::string &periodId, const std:
7070
* @brief PrivateCDAIObjectMPD constructor
7171
*/
7272
PrivateCDAIObjectMPD::PrivateCDAIObjectMPD(AampLogManager* logObj, PrivateInstanceAAMP* aamp) : mLogObj(logObj),mAamp(aamp),mDaiMtx(), mIsFogTSB(false), mAdBreaks(), mPeriodMap(), mCurPlayingBreakId(), mAdObjThreadID(0), mAdFailed(false), mCurAds(nullptr),
73-
mCurAdIdx(-1), mContentSeekOffset(0), mAdState(AdState::OUTSIDE_ADBREAK),mPlacementObj(), mAdFulfillObj(),mAdtoInsertInNextBreak()
73+
mCurAdIdx(-1), mContentSeekOffset(0), mAdState(AdState::OUTSIDE_ADBREAK),mPlacementObj(), mAdFulfillObj(),mAdtoInsertInNextBreak(), mAdObjThreadStarted(false)
7474
{
7575
mAamp->CurlInit(eCURLINSTANCE_DAI,1,mAamp->GetNetworkProxy());
7676
}
@@ -80,14 +80,14 @@ PrivateCDAIObjectMPD::PrivateCDAIObjectMPD(AampLogManager* logObj, PrivateInstan
8080
*/
8181
PrivateCDAIObjectMPD::~PrivateCDAIObjectMPD()
8282
{
83-
if(mAdObjThreadID)
83+
if(mAdObjThreadStarted)
8484
{
8585
int rc = pthread_join(mAdObjThreadID, NULL);
8686
if (rc != 0)
8787
{
8888
AAMPLOG_ERR("***pthread_join failed, returned %d", rc);
8989
}
90-
mAdObjThreadID = 0;
90+
mAdObjThreadStarted = false;
9191
}
9292
mAamp->CurlTerm(eCURLINSTANCE_DAI);
9393
}
@@ -775,15 +775,15 @@ void PrivateCDAIObjectMPD::SetAlternateContents(const std::string &periodId, con
775775
}
776776
else
777777
{
778-
if(mAdObjThreadID)
778+
if(mAdObjThreadStarted)
779779
{
780780
//Clearing the previous thread
781781
int rc = pthread_join(mAdObjThreadID, NULL);
782782
if(rc != 0) //CID:101068 - Resolving the local variable rc initialized but not used
783783
{
784784
AAMPLOG_ERR("pthread_join(mAdObjThreadID) failed , errno = %d, %s , Rejecting promise.",errno,strerror(errno));
785785
}
786-
mAdObjThreadID = 0;
786+
mAdObjThreadStarted = false;
787787
}
788788
if(isAdBreakObjectExist(periodId))
789789
{
@@ -804,6 +804,10 @@ void PrivateCDAIObjectMPD::SetAlternateContents(const std::string &periodId, con
804804
{
805805
AAMPLOG_ERR(" pthread_create(FulFillAdObject) failed, errno = %d, %s. Rejecting promise.", errno, strerror(errno));
806806
}
807+
else
808+
{
809+
mAdObjThreadStarted = true;
810+
}
807811
}
808812
if(ret != 0)
809813
{

admanager_mpd.h

+1
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ class PrivateCDAIObjectMPD
286286
std::unordered_map<std::string, Period2AdData> mPeriodMap; /**< periodId to Ad map */
287287
std::string mCurPlayingBreakId; /**< Currently playing Ad */
288288
pthread_t mAdObjThreadID; /**< ThreadId of Ad fulfillment */
289+
bool mAdObjThreadStarted; /**< Flag denotes if ad object thread is started */
289290
bool mAdFailed; /**< Current Ad playback failed flag */
290291
std::shared_ptr<std::vector<AdNode>> mCurAds; /**< Vector of ads from the current Adbreak */
291292
int mCurAdIdx; /**< Currently playing Ad index */

fragmentcollector_mpd.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -6318,8 +6318,11 @@ void StreamAbstractionAAMP_MPD::ProcessEAPLicenseRequest()
63186318
if(!deferredDRMRequestThreadStarted)
63196319
{
63206320
// wait for thread to complete and create a new thread
6321-
if ((deferredDRMRequestThread!= NULL) && (deferredDRMRequestThread->joinable()))
6321+
if ((deferredDRMRequestThread != NULL) && (deferredDRMRequestThread->joinable()))
63226322
{
6323+
//Need to check if we ever hit this code block, there is a possible delay
6324+
//since mAbortDeferredLicenseLoop is not updated. Add a log for now for monitoring
6325+
AAMPLOG_INFO("Trying to join deferred DRM request thread with possible time delay!");
63236326
deferredDRMRequestThread->join();
63246327
SAFE_DELETE(deferredDRMRequestThread);
63256328
}
@@ -6400,7 +6403,6 @@ void StreamAbstractionAAMP_MPD::StartDeferredDRMRequestThread(MediaType mediaTyp
64006403
}
64016404
}
64026405
while(!exitLoop);
6403-
deferredDRMRequestThreadStarted = false;
64046406
}
64056407
#endif
64066408

@@ -9349,7 +9351,7 @@ void StreamAbstractionAAMP_MPD::FetcherLoop()
93499351
while (!exitFetchLoop && !liveMPDRefresh)
93509352
{
93519353
bool bCacheFullState = true;
9352-
std::thread *parallelDownload[AAMP_TRACK_COUNT];
9354+
std::thread *parallelDownload[AAMP_TRACK_COUNT] = { nullptr };
93539355

93549356
for (int trackIdx = (mNumberOfTracks - 1); trackIdx >= 0; trackIdx--)
93559357
{

0 commit comments

Comments
 (0)