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

Commit 7f63b9a9 authored by Narayan Kamath's avatar Narayan Kamath
Browse files

CameraMetadataNative: Fix FD leak in dump.

Always close the read end of the socketpair. In addition, return
early if pthread_create fails. If we don't do this, we risk blocking
forever on the read() and/or calling pthread_join on an undefined
pthread_t.

Test: run cts -m CtsCameraTestCases;

Change-Id: I9adb872ac2dbca2474e04707b77945b0a08d9432
parent 5c5b6dae
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -442,10 +442,12 @@ static void CameraMetadata_dump(JNIEnv *env, jobject thiz) {

        if (threadRet != 0) {
            close(writeFd);
            close(readFd);

            jniThrowExceptionFmt(env, "java/io/IOException",
                    "Failed to create thread for writing (errno = %#x, message = '%s')",
                    threadRet, strerror(threadRet));
            return;
        }
    }

@@ -476,6 +478,8 @@ static void CameraMetadata_dump(JNIEnv *env, jobject thiz) {
        } else if (!logLine.isEmpty()) {
            ALOGD("%s", logLine.string());
        }

        close(readFd);
    }

    int res;