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

Commit 0ef554e7 authored by Dave Burke's avatar Dave Burke Committed by Android Git Automerger
Browse files

am fd48718b: am c81f70b6: am 716bae33: am d84ab8b1: am e09e20ee: Merge "Revert...

am fd48718b: am c81f70b6: am 716bae33: am d84ab8b1: am e09e20ee: Merge "Revert "Fix memory leak where we close the descriptor instead of the file."" into lmp-dev

* commit 'fd48718bdae13cf14cb57ec8d7822dbe50daae0d':
  Revert "Fix memory leak where we close the descriptor instead of the file."
parents ce455700 b168fa0c
Loading
Loading
Loading
Loading
+5 −11
Original line number Diff line number Diff line
@@ -478,7 +478,7 @@ static jobject nativeDecodeFileDescriptor(JNIEnv* env, jobject clazz, jobject fi

    NPE_CHECK_RETURN_ZERO(env, fileDescriptor);

    int descriptor = jniGetFDFromFileDescriptor(env, fileDescriptor);
    jint descriptor = jniGetFDFromFileDescriptor(env, fileDescriptor);

    struct stat fdStat;
    if (fstat(descriptor, &fdStat) == -1) {
@@ -486,22 +486,16 @@ static jobject nativeDecodeFileDescriptor(JNIEnv* env, jobject clazz, jobject fi
        return nullObjectReturn("fstat return -1");
    }

    // Duplicate the descriptor here to prevent leaking memory. A leak occurs
    // if we only close the file descriptor and not the file object it is used to
    // create.  If we don't explicitly clean up the file (which in turn closes the
    // descriptor) the buffers allocated internally by fseek will be leaked.
    int dupDescriptor = dup(descriptor);
    // Restore the descriptor's offset on exiting this function.
    AutoFDSeek autoRestore(descriptor);

    FILE* file = fdopen(dupDescriptor, "r");
    FILE* file = fdopen(descriptor, "r");
    if (file == NULL) {
        // cleanup the duplicated descriptor since it will not be closed when the
        // file is cleaned up (fclose).
        close(dupDescriptor);
        return nullObjectReturn("Could not open file");
    }

    SkAutoTUnref<SkFILEStream> fileStream(new SkFILEStream(file,
                         SkFILEStream::kCallerPasses_Ownership));
                         SkFILEStream::kCallerRetains_Ownership));

    // Use a buffered stream. Although an SkFILEStream can be rewound, this
    // ensures that SkImageDecoder::Factory never rewinds beyond the