Skip to content

Commit f4183a5

Browse files
Fix native memory leak in Uint64ArrayRW
Bug: 377547685 Test: adb shell dumpsys batterystats --usage; adb shell dumpsys -t 60 meminfo --unreachable `adb shell pidof system_server` | grep "unreachable allocations" Flag: EXEMPT bugfix Change-Id: I2287379427a8de732eda866dfcc3d4129dfb890d
1 parent 8353512 commit f4183a5

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

libs/battery/LongArrayMultiStateCounter.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@ Uint64ArrayRW &Uint64ArrayRW::operator=(const Uint64Array &t) {
4646
}
4747
if (mSize != 0) {
4848
if (t.data() != nullptr) {
49-
mData = new uint64_t[mSize];
49+
if (mData == nullptr) {
50+
mData = new uint64_t[mSize];
51+
}
5052
memcpy(mData, t.data(), mSize * sizeof(uint64_t));
5153
} else {
54+
delete[] mData;
5255
mData = nullptr;
5356
}
5457
}

0 commit comments

Comments
 (0)