8be5eabe6a4fc60c56a3b32794bb6677e26f6eab |
|
27-Mar-2017 |
Brian Duddie <bduddie@google.com> |
Fix incorrect usage of assignment, move in containers Containers like DynamicVector were using the assignment operator in multiple places to initialize memory. This is not valid, as assignment assumes that the receiving object has already been constructed. This manifested in use of DynamicVector<UniquePtr>, where UniquePtr's move assignment operator would call memoryFree on its pointer if not null - if its pointer was some non-zero uninitialized memory, this would lead to memory corruption and a likely crash. Resolve this issue by correcting all instances where assignment was used on uninitialized memory to use placement new to properly construct these objects. Also, make updates to places where containers assumed that move/copy assignment/construction was supported by the contained type to check that condition and select the appropriate option. Finally, fix the tests that were written with the assumption that certain operations would use assignment when they should have used construction, and also increase overall test coverage to ensure this issue does not recur. Test: run tests and simulator with valgrind Change-Id: Ia2803ab78a02065acab384e536c3259a52f7c863
/system/chre/util/include/chre/util/memory.h
|