Skip to content

Commit 968c9cc

Browse files
Treehugger RobotAndroid (Google) Code Review
authored andcommitted
Merge "Fix native memory leak in Uint64ArrayRW" into main
2 parents 7d24e7e + f4183a5 commit 968c9cc

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)