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

Commit 5dd792c8 authored by Akshata Kadam's avatar Akshata Kadam Committed by Ayushi Khopkar
Browse files

ndk_sync_codec_fuzzer : Resolved Direct Memory Leak Issue

mFormat in NdkMediaCodecFuzzerBase class wasn't freed in
some cases. This CL creates a destructor for NdkMediaCodecFuzzerBase
and adds a free for mFormat in destructor. Also removes local call
to AMediaFormat_delete in ndk_sync_codec_fuzzer.

Test: $ANDROID_HOST_OUT/fuzz/x86_64/ndk_sync_codec_fuzzer/ndk_sync_codec_fuzzer CORPUS_DIR
Bug: 243215191

Change-Id: I84608dc934b21b71769a7d798af3f9bbf476d37e
(cherry picked from commit 03e1c251d2e090402a2bad30e8bee8924e065622)
parent d01cbef7
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -46,6 +46,11 @@ class NdkMediaCodecFuzzerBase {
    AMediaCodec* createCodec(bool isEncoder, bool isCodecForClient);
    AMediaFormat* getCodecFormat() { return mFormat; };
    void setFdp(FuzzedDataProvider* fdp) { mFdp = fdp; }
    ~NdkMediaCodecFuzzerBase() {
        if (mFormat) {
            AMediaFormat_delete(mFormat);
        }
    }

  private:
    AMediaCodec* createAMediaCodecByname(bool isEncoder, bool isCodecForClient);
+1 −5
Original line number Diff line number Diff line
@@ -41,14 +41,13 @@ class NdkSyncCodecFuzzer : public NdkMediaCodecFuzzerBase {

void NdkSyncCodecFuzzer::invokekSyncCodecAPIs(bool isEncoder) {
    ANativeWindow* nativeWindow = nullptr;
    AMediaFormat* format = getCodecFormat();
    int32_t numOfFrames = mFdp.ConsumeIntegralInRange<size_t>(kMinIterations, kMaxIterations);
    int32_t count = 0;
    while (++count <= numOfFrames) {
        int32_t ndkcodecAPI = mFdp.ConsumeIntegralInRange<size_t>(kMinAPICase, kMaxNdkCodecAPIs);
        switch (ndkcodecAPI) {
            case 0: {  // configure the codec
                AMediaCodec_configure(mCodec, format, nativeWindow, nullptr /* crypto */,
                AMediaCodec_configure(mCodec, getCodecFormat(), nativeWindow, nullptr /* crypto */,
                                      (isEncoder ? AMEDIACODEC_CONFIGURE_FLAG_ENCODE : 0));
                break;
            }
@@ -119,9 +118,6 @@ void NdkSyncCodecFuzzer::invokekSyncCodecAPIs(bool isEncoder) {
    if (nativeWindow) {
        ANativeWindow_release(nativeWindow);
    }
    if (format) {
        AMediaFormat_delete(format);
    }
}

void NdkSyncCodecFuzzer::invokeSyncCodeConfigAPI() {