Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3e18a9de authored by Johannes Carlsson's avatar Johannes Carlsson Committed by Steve Kondik
Browse files

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.
parent 80e8ab4f
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
@@ -571,7 +571,10 @@ static void *eventLoopMain(void *ptr) {
                                NULL, NULL, NULL, NULL, NULL);
                        tearDownEventLoop(nat);
                        nat->vm->DetachCurrentThread();
                        shutdown(nat->controlFdR,SHUT_RDWR);

                        int fd = nat->controlFdR;
                        nat->controlFdr = 0;
                        close(fd);
                        return NULL;
                    }
                    case EVENT_LOOP_ADD:
@@ -660,9 +663,12 @@ static jboolean startEventLoopNative(JNIEnv *env, jobject object) {

done:
    if (JNI_FALSE == result) {
        if (nat->controlFdW || nat->controlFdR) {
            shutdown(nat->controlFdW, SHUT_RDWR);
        if (nat->controlFdW) {
            close(nat->controlFdW);
            nat->controlFdW = 0;
        }
        if (nat->controlFdR) {
            close(nat->controlFdR);
            nat->controlFdR = 0;
        }
        if (nat->me) env->DeleteGlobalRef(nat->me);
@@ -699,9 +705,10 @@ static void stopEventLoopNative(JNIEnv *env, jobject object) {
        nat->watchData = NULL;
        nat->pollDataSize = 0;
        nat->pollMemberCount = 0;
        shutdown(nat->controlFdW, SHUT_RDWR);

        int fd = nat->controlFdW;
        nat->controlFdW = 0;
        nat->controlFdR = 0;
        close(fd);
    }
    pthread_mutex_unlock(&(nat->thread_mutex));
#endif // HAVE_BLUETOOTH