Correct cleanup when compacting metrics attributes
Correct management of compacted media metrics attributes; ensure
proper release of a stale reference after copying it down into
a spot vacated as part of a deletion.
Bug: 67110197
Test: logcat to see it trip through the fix
Change-Id: I19031ebf257e958141524458da6b808fa741cce7
diff --git a/media/libmediametrics/MediaAnalyticsItem.cpp b/media/libmediametrics/MediaAnalyticsItem.cpp
index 30a31e6..31ac4e5 100644
--- a/media/libmediametrics/MediaAnalyticsItem.cpp
+++ b/media/libmediametrics/MediaAnalyticsItem.cpp
@@ -100,7 +100,7 @@
// clean attributes
// contents of the attributes
- for (size_t i = 0 ; i < mPropSize; i++ ) {
+ for (size_t i = 0 ; i < mPropCount; i++ ) {
clearProp(&mProps[i]);
}
// the attribute records themselves
@@ -300,7 +300,8 @@
clearProp(prop);
if (i != mPropCount-1) {
// in the middle, bring last one down to fill gap
- mProps[i] = mProps[mPropCount-1];
+ copyProp(prop, &mProps[mPropCount-1]);
+ clearProp(&mProps[mPropCount-1]);
}
mPropCount--;
return true;