Skip to content

Commit ed0d1ab

Browse files
Johannes CarlssonJohan Redestig
authored andcommitted
Everytime Bluetooth was turned off two file descriptors were not closed
Using close instead of shutdown on the file descriptors and only clear the file descriptor that was closed. If both file descriptors are cleared the thread will not be able to close it.
1 parent 7bb2581 commit ed0d1ab

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

core/jni/android_server_BluetoothEventLoop.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,10 @@ static void *eventLoopMain(void *ptr) {
564564
NULL, NULL, NULL, NULL, NULL);
565565
tearDownEventLoop(nat);
566566
nat->vm->DetachCurrentThread();
567-
shutdown(nat->controlFdR,SHUT_RDWR);
567+
568+
int fd = nat->controlFdR;
569+
nat->controlFdR = 0;
570+
close(fd);
568571
return NULL;
569572
}
570573
case EVENT_LOOP_ADD:
@@ -653,9 +656,12 @@ static jboolean startEventLoopNative(JNIEnv *env, jobject object) {
653656

654657
done:
655658
if (JNI_FALSE == result) {
656-
if (nat->controlFdW || nat->controlFdR) {
657-
shutdown(nat->controlFdW, SHUT_RDWR);
659+
if (nat->controlFdW) {
660+
close(nat->controlFdW);
658661
nat->controlFdW = 0;
662+
}
663+
if (nat->controlFdR) {
664+
close(nat->controlFdR);
659665
nat->controlFdR = 0;
660666
}
661667
if (nat->me) env->DeleteGlobalRef(nat->me);
@@ -692,9 +698,10 @@ static void stopEventLoopNative(JNIEnv *env, jobject object) {
692698
nat->watchData = NULL;
693699
nat->pollDataSize = 0;
694700
nat->pollMemberCount = 0;
695-
shutdown(nat->controlFdW, SHUT_RDWR);
701+
702+
int fd = nat->controlFdW;
696703
nat->controlFdW = 0;
697-
nat->controlFdR = 0;
704+
close(fd);
698705
}
699706
pthread_mutex_unlock(&(nat->thread_mutex));
700707
#endif // HAVE_BLUETOOTH

0 commit comments

Comments
 (0)