diff options
author | Marco Nelissen <marcone@google.com> | 2014-05-06 10:33:07 -0700 |
---|---|---|
committer | Marco Nelissen <marcone@google.com> | 2014-05-06 10:37:04 -0700 |
commit | 7c9b141d551fde406f199f0dd21582f8551aea23 (patch) | |
tree | a85ae2f96546c0a1f3b81532f4dda22a72d942a5 /media/ndk | |
parent | 91d8ec1860e8186cd202f9415f6b41c20fbd54fb (diff) | |
download | frameworks_av-7c9b141d551fde406f199f0dd21582f8551aea23.zip frameworks_av-7c9b141d551fde406f199f0dd21582f8551aea23.tar.gz frameworks_av-7c9b141d551fde406f199f0dd21582f8551aea23.tar.bz2 |
MediaFormat owns its strings
Have MediaFormat own the strings it returns from toString and getString,
reducing the chance of memory leaks.
Change-Id: I0ddd593874c8b3af0b7714f2d8a106edf8121108
Diffstat (limited to 'media/ndk')
-rw-r--r-- | media/ndk/NdkMediaFormat.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/media/ndk/NdkMediaFormat.cpp b/media/ndk/NdkMediaFormat.cpp index 359f37e..6f69f8d 100644 --- a/media/ndk/NdkMediaFormat.cpp +++ b/media/ndk/NdkMediaFormat.cpp @@ -34,6 +34,8 @@ using namespace android; struct AMediaFormat { sp<AMessage> mFormat; + String8 mDebug; + KeyedVector<String8, String8> mStringCache; }; extern "C" { @@ -135,7 +137,8 @@ const char* AMediaFormat_toString(AMediaFormat *mData) { } } ret.append("}"); - return strdup(ret.string()); + mData->mDebug = ret; + return mData->mDebug.string(); } bool AMediaFormat_getInt32(AMediaFormat* mData, const char *name, int32_t *out) { @@ -159,9 +162,19 @@ bool AMediaFormat_getSize(AMediaFormat* mData, const char *name, size_t *out) { } bool AMediaFormat_getString(AMediaFormat* mData, const char *name, const char **out) { + + for (size_t i = 0; i < mData->mStringCache.size(); i++) { + if (strcmp(mData->mStringCache.keyAt(i).string(), name) == 0) { + mData->mStringCache.removeItemsAt(i, 1); + break; + } + } + AString tmp; if (mData->mFormat->findString(name, &tmp)) { - *out = strdup(tmp.c_str()); + String8 ret(tmp.c_str()); + mData->mStringCache.add(String8(name), ret); + *out = ret.string(); return true; } return false; |