0

For benchmarking purposes I repeat loading an .wav-file, processing it offline and saving the output by using the SuperpoweredSDK. But after some iterations (in my case 4) I get the error "A/libc: invalid address or address of corrupt block 0x5e825000 passed to dlfree" when I try to release the shortIntBuffer.

extern "C" JNIEXPORT void JNICALL
Java_com_example_sebas_superpoweredtest_MainActivity_testDecoderReuse(JNIEnv *env, jobject instance,
                                                                  jstring apkPath_,
                                                                  jlong fileOffset,
                                                                  jlong fileLength,
                                                                  jstring outputFileName_) {

    const char *apkPath = env->GetStringUTFChars(apkPath_, 0);
    const char *outputFileName = env->GetStringUTFChars(outputFileName_, 0);

    SuperpoweredDecoder decoder;
    short int* shortIntBuffer;
    FILE* fd;

    for(int i = 0; i < 100; ++i) {

        __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, "RUN %d", i+1);

        //open InputFile
        const char *openError = decoder.open(apkPath, false, fileOffset, fileLength);
        if (openError) {
            __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "%s", openError);
            return;
        };

        shortIntBuffer = new short int[decoder.samplesPerFrame * 4 + 16384] {0};

        fd = createWAV(outputFileName, decoder.samplerate, 2);
        if (!fd) {
            __android_log_print(ANDROID_LOG_ERROR,LOG_TAG, "Failed creating File %s", outputFileName);
            return;
        };

        //process samples
        unsigned int samplesDecoded;

        while (true) {
            // Decode one frame. samplesDecoded will be overwritten with the actual decoded number of samples.
            samplesDecoded = decoder.samplesPerFrame;
            if (decoder.decode(shortIntBuffer, &samplesDecoded) == SUPERPOWEREDDECODER_ERROR) {
                __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Error while decoding samples.");
                break;
            }

            if (samplesDecoded < 1) break;

            // Write the audio to disk.
            fwrite(shortIntBuffer, 1, samplesDecoded * 4, fd);
        };

        //close resources
        if(fd) {
            closeWAV(fd);
            __android_log_print(ANDROID_LOG_ERROR,LOG_TAG, "Closed wav.");
        }


        delete[](shortIntBuffer); // <- SIGSEGV (signal SIGSEGV: invalid address (fault address: 0xdeadbaad))
        __android_log_print(ANDROID_LOG_ERROR,LOG_TAG, "Deleted shortInBuffer");


    }

    env->ReleaseStringUTFChars(apkPath_, apkPath);
    env->ReleaseStringUTFChars(outputFileName_, outputFileName);
}

I don't understand why the code works fine for the first iterations but not for all iterations. I would be grateful to hear from you to solve this problem.

Thanks in advance

This is the LLDB-Frame when I get the message: "Fatal signal 11 (SIGSEGV) at 0xfde0fdec (code=1), thread 9779 (uperpoweredtest)"

LLDB Frame

Sebastian
  • 183
  • 1
  • 12
  • 1
    I recommend to instantiate the decoder and the int buffer "the classic way", that is using new SuperpoweredDecoder() for the decoder, and malloc/free for the int buffer. Perhaps you'll get a more useful log this way. – Gabor Szanto Feb 11 '17 at 08:19
  • 1
    I tested the code now by using new SuperpoweredDecoder() for the decoder and malloc/free for the short int buffer as recommened. I still get the same error messages but now for i=2. I added the lldb frame to my question. A simple workaroud would be instancing and deleting a SuperpoweredDecoder in each iteration which works. – Sebastian Feb 13 '17 at 20:22
  • 2
    Yes, use a new SuperpoweredDecoder instance for every iteration. Creating a new instance is very quick. – Gabor Szanto Feb 14 '17 at 07:05
  • 1
    Thanks for the fast reply. – Sebastian Feb 14 '17 at 10:54

0 Answers0