Skip to content

Commit 9f44fd6

Browse files
committed
Fixed memory leak and redundant JNI attach in video decoding.
1 parent d941d22 commit 9f44fd6

1 file changed

Lines changed: 2 additions & 17 deletions

File tree

TMessagesProj/jni/gifvideo.cpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ typedef struct VideoInfo {
4848

4949
~VideoInfo() {
5050
if (video_dec_ctx) {
51-
avcodec_close(video_dec_ctx);
52-
video_dec_ctx = nullptr;
51+
avcodec_free_context(&video_dec_ctx);
5352
}
5453
if (fmt_ctx) {
5554
avformat_close_input(&fmt_ctx);
@@ -919,21 +918,7 @@ extern "C" JNIEXPORT jint JNICALL Java_org_telegram_ui_Components_AnimatedFileDr
919918
//info->has_decoded_frames = false;
920919
while (!info->stopped && triesCount != 0) {
921920
if (info->stream != nullptr) {
922-
JNIEnv *jniEnv = nullptr;
923-
JavaVMAttachArgs jvmArgs;
924-
jvmArgs.version = JNI_VERSION_1_6;
925-
926-
bool attached;
927-
if (JNI_EDETACHED == javaVm->GetEnv((void **) &jniEnv, JNI_VERSION_1_6)) {
928-
javaVm->AttachCurrentThread(&jniEnv, &jvmArgs);
929-
attached = true;
930-
} else {
931-
attached = false;
932-
}
933-
jboolean canceled = jniEnv->CallBooleanMethod(info->stream, jclass_AnimatedFileDrawableStream_isCanceled);
934-
if (attached) {
935-
javaVm->DetachCurrentThread();
936-
}
921+
jboolean canceled = env->CallBooleanMethod(info->stream, jclass_AnimatedFileDrawableStream_isCanceled);
937922
if (canceled) {
938923
return 0;
939924
}

0 commit comments

Comments
 (0)