Skip to content

Commit 0939024

Browse files
committed
fix a few bugs
1 parent 1fc4831 commit 0939024

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

samples/Common.c

-5
Original file line numberDiff line numberDiff line change
@@ -1025,11 +1025,6 @@ STATUS freeSampleConfiguration(PSampleConfiguration* ppSampleConfiguration)
10251025
MUTEX_LOCK(pSampleConfiguration->sampleConfigurationObjLock);
10261026
locked = TRUE;
10271027
}
1028-
// Cancel the media thread
1029-
if(!(pSampleConfiguration->mediaThreadStarted)) {
1030-
DLOGD("Canceling media thread");
1031-
THREAD_CANCEL(pSampleConfiguration->mediaSenderTid);
1032-
}
10331028

10341029
for (i = 0; i < pSampleConfiguration->streamingSessionCount; ++i) {
10351030
retStatus = gatherIceServerStats(pSampleConfiguration->sampleStreamingSessionList[i]);

samples/kvsWebRTCClientMaster.c

+14
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,20 @@ INT32 main(INT32 argc, CHAR* argv[])
122122
// Kick of the termination sequence
123123
ATOMIC_STORE_BOOL(&pSampleConfiguration->appTerminateFlag, TRUE);
124124

125+
if (IS_VALID_MUTEX_VALUE(pSampleConfiguration->sampleConfigurationObjLock)) {
126+
MUTEX_LOCK(pSampleConfiguration->sampleConfigurationObjLock);
127+
}
128+
129+
// Cancel the media thread
130+
if (pSampleConfiguration->mediaThreadStarted) {
131+
DLOGD("Canceling media thread");
132+
THREAD_CANCEL(pSampleConfiguration->mediaSenderTid);
133+
}
134+
135+
if (IS_VALID_MUTEX_VALUE(pSampleConfiguration->sampleConfigurationObjLock)) {
136+
MUTEX_UNLOCK(pSampleConfiguration->sampleConfigurationObjLock);
137+
}
138+
125139
if (pSampleConfiguration->mediaSenderTid != INVALID_TID_VALUE) {
126140
THREAD_JOIN(pSampleConfiguration->mediaSenderTid, NULL);
127141
}

src/source/Ice/ConnectionListener.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,10 @@ PVOID connectionListenerReceiveDataRoutine(PVOID arg)
374374

375375
CleanUp:
376376

377-
if (pConnectionListener != NULL) {
377+
// The check for valid mutex is necessary because when we're in freeConnectionListener
378+
// we may free the mutex in another thread so by the time we get here accessing the lock
379+
// will result in accessing a resource after it has been freed
380+
if (pConnectionListener != NULL && IS_VALID_MUTEX_VALUE(pConnectionListener->lock)) {
378381
// As TID is 64 bit we can't atomically update it and need to do it under the lock
379382
MUTEX_LOCK(pConnectionListener->lock);
380383
pConnectionListener->receiveDataRoutine = INVALID_TID_VALUE;

0 commit comments

Comments
 (0)