-
Norvald H. Ryeng authored
Problem: Inplace_vector::delete_all_objects() leaks memory if the last array is full. The elements of the vector are deleted by looping through the list of arrays of objects, and, for each array, looping through all objects of that array and calling the destructor. Each array, except the last, is expected to be full. The number of used positions in the last array is calculated as the total number of elements in the vector modulo the array size. After destructing each object, the array is freed. This works for all vectors unless the last array of the vector is full. In that case, the number of used positions is calculated to be 0, and none of the elements are destructed. If these objects have allocated memory that should be freed by their destructors, that memory is lost when the array is freed. Fix: Destruct all elements of all arrays.
Norvald H. Ryeng authoredProblem: Inplace_vector::delete_all_objects() leaks memory if the last array is full. The elements of the vector are deleted by looping through the list of arrays of objects, and, for each array, looping through all objects of that array and calling the destructor. Each array, except the last, is expected to be full. The number of used positions in the last array is calculated as the total number of elements in the vector modulo the array size. After destructing each object, the array is freed. This works for all vectors unless the last array of the vector is full. In that case, the number of used positions is calculated to be 0, and none of the elements are destructed. If these objects have allocated memory that should be freed by their destructors, that memory is lost when the array is freed. Fix: Destruct all elements of all arrays.
Loading