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
This commit is contained in:
wfeng6
2012-06-25 18:48:49 +08:00
committed by Shuo Gao
parent a950daf5c1
commit c96a7294a4
3 changed files with 17 additions and 0 deletions

View File

@@ -1853,6 +1853,9 @@ videoEditClasses_getEditSettings(
// Get the clip settings.
videoEditClasses_getClipSettings(pResult, pEnv, clipSettings,
&pSettings->pClipList[i]);
// Free the local references to avoid memory leaks
pEnv->DeleteLocalRef(clipSettings);
}
}
}
@@ -1877,6 +1880,9 @@ videoEditClasses_getEditSettings(
// Get the transition settings.
videoEditClasses_getTransitionSettings(pResult, pEnv,
transitionSettings, &pSettings->pTransitionList[i]);
// Free the local references to avoid memory leaks
pEnv->DeleteLocalRef(transitionSettings);
}
}
}
@@ -1900,6 +1906,9 @@ videoEditClasses_getEditSettings(
// Get the effect settings.
videoEditClasses_getEffectSettings(pResult, pEnv, effectSettings,
&pSettings->Effects[i]);
// Free the local references to avoid memory leaks
pEnv->DeleteLocalRef(effectSettings);
}
}
}

View File

@@ -387,6 +387,9 @@ videoEditJava_getString(
(*pLength) = length;
}
}
// Delete local references to avoid memory leaks
pEnv->DeleteLocalRef(string);
}
// Return the string.

View File

@@ -380,6 +380,9 @@ getClipSetting(
pEnv->GetIntField(object,fid);
M4OSA_TRACE1_1("videoRotation = %d",
pSettings->ClipProperties.videoRotationDegrees);
// Free the local references to avoid memory leaks
pEnv->DeleteLocalRef(clazz);
}
static void jniPreviewProgressCallback (void* cookie, M4OSA_UInt32 msgType,
@@ -1849,7 +1852,9 @@ videoEditor_populateSettings(
"not initialized");
if (needToBeLoaded) {
getClipSetting(pEnv,properties, pContext->pEditSettings->pClipList[i]);
pEnv->DeleteLocalRef(properties);
} else {
pEnv->DeleteLocalRef(properties);
goto videoEditor_populateSettings_cleanup;
}
}