Skip to content

Commit c96a729

Browse files
wayfengshuogao
authored andcommitted
To avoid the JNI memory leaks in video editor codes
There is a protential memory leak in video editor JNI codes. When importing so many video clips, the number of local reference will exceed 512, which will cause the Dalvik virtual machine crash. The patch will free each local reference when it's no longer used to avoid memory leaks. Change-Id: Iecd986c83f05a1103641746d6d43eef0a9c5ee40 Author: Wei Feng <wei.feng@intel.com> Signed-off-by: Wei Feng <wei.feng@intel.com> Singed-off-by: Shuo Gao <shuo.gao@intel.com> Signed-off-by: Bruce Beare <bruce.j.beare@intel.com> Signed-off-by: Jack Ren <jack.ren@intel.com> Author-tracking-BZ: 40786
1 parent a950daf commit c96a729

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

media/jni/mediaeditor/VideoEditorClasses.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,6 +1853,9 @@ videoEditClasses_getEditSettings(
18531853
// Get the clip settings.
18541854
videoEditClasses_getClipSettings(pResult, pEnv, clipSettings,
18551855
&pSettings->pClipList[i]);
1856+
1857+
// Free the local references to avoid memory leaks
1858+
pEnv->DeleteLocalRef(clipSettings);
18561859
}
18571860
}
18581861
}
@@ -1877,6 +1880,9 @@ videoEditClasses_getEditSettings(
18771880
// Get the transition settings.
18781881
videoEditClasses_getTransitionSettings(pResult, pEnv,
18791882
transitionSettings, &pSettings->pTransitionList[i]);
1883+
1884+
// Free the local references to avoid memory leaks
1885+
pEnv->DeleteLocalRef(transitionSettings);
18801886
}
18811887
}
18821888
}
@@ -1900,6 +1906,9 @@ videoEditClasses_getEditSettings(
19001906
// Get the effect settings.
19011907
videoEditClasses_getEffectSettings(pResult, pEnv, effectSettings,
19021908
&pSettings->Effects[i]);
1909+
1910+
// Free the local references to avoid memory leaks
1911+
pEnv->DeleteLocalRef(effectSettings);
19031912
}
19041913
}
19051914
}

media/jni/mediaeditor/VideoEditorJava.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,9 @@ videoEditJava_getString(
387387
(*pLength) = length;
388388
}
389389
}
390+
391+
// Delete local references to avoid memory leaks
392+
pEnv->DeleteLocalRef(string);
390393
}
391394

392395
// Return the string.

media/jni/mediaeditor/VideoEditorMain.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,9 @@ getClipSetting(
380380
pEnv->GetIntField(object,fid);
381381
M4OSA_TRACE1_1("videoRotation = %d",
382382
pSettings->ClipProperties.videoRotationDegrees);
383+
384+
// Free the local references to avoid memory leaks
385+
pEnv->DeleteLocalRef(clazz);
383386
}
384387

385388
static void jniPreviewProgressCallback (void* cookie, M4OSA_UInt32 msgType,
@@ -1849,7 +1852,9 @@ videoEditor_populateSettings(
18491852
"not initialized");
18501853
if (needToBeLoaded) {
18511854
getClipSetting(pEnv,properties, pContext->pEditSettings->pClipList[i]);
1855+
pEnv->DeleteLocalRef(properties);
18521856
} else {
1857+
pEnv->DeleteLocalRef(properties);
18531858
goto videoEditor_populateSettings_cleanup;
18541859
}
18551860
}

0 commit comments

Comments
 (0)