diff options
author | Mathias Agopian <mathias@google.com> | 2010-03-29 13:45:18 -0700 |
---|---|---|
committer | Alex Ray <aray@google.com> | 2013-07-30 13:56:53 -0700 |
commit | 15d0edcba018d99a356077c8769148e769585a48 (patch) | |
tree | f6ab56ac9503cd3e77178690c5a2774fe6d258af /libs | |
parent | 68f64818203cf7d2ef1b4707448191829221898e (diff) | |
download | system_core-15d0edcba018d99a356077c8769148e769585a48.zip system_core-15d0edcba018d99a356077c8769148e769585a48.tar.gz system_core-15d0edcba018d99a356077c8769148e769585a48.tar.bz2 |
fix [2542425] memory leak during video recording
Vector::sort() is using _do_copy() incorrectly; _do_copy() calls the
copy constructor, not the assignment operator, so we need to destroy
the "destination" before copying the item.
Change-Id: Iaeeac808fa5341a7d219edeba4aa63d44f31473c
Diffstat (limited to 'libs')
-rw-r--r-- | libs/utils/VectorImpl.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/libs/utils/VectorImpl.cpp b/libs/utils/VectorImpl.cpp index 2c2d667..0322af7 100644 --- a/libs/utils/VectorImpl.cpp +++ b/libs/utils/VectorImpl.cpp @@ -173,9 +173,10 @@ status_t VectorImpl::sort(VectorImpl::compar_r_t cmp, void* state) if (!array) return NO_MEMORY; temp = malloc(mItemSize); if (!temp) return NO_MEMORY; - _do_construct(temp, 1); item = reinterpret_cast<char*>(array) + mItemSize*(i); curr = reinterpret_cast<char*>(array) + mItemSize*(i-1); + } else { + _do_destroy(temp, 1); } _do_copy(temp, item, 1); @@ -183,12 +184,14 @@ status_t VectorImpl::sort(VectorImpl::compar_r_t cmp, void* state) ssize_t j = i-1; void* next = reinterpret_cast<char*>(array) + mItemSize*(i); do { + _do_destroy(next, 1); _do_copy(next, curr, 1); next = curr; --j; curr = reinterpret_cast<char*>(array) + mItemSize*(j); } while (j>=0 && (cmp(curr, temp, state) > 0)); + _do_destroy(next, 1); _do_copy(next, temp, 1); } i++; |