Bug #84034 Use std::is_trivially_destructible in Prealloced_array
Submitted: 1 Dec 2016 23:24 Modified: 6 Dec 2016 19:37
Reporter: Knut Anders Hatlen Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Compiling Severity:S3 (Non-critical)
Version:8.0.1 OS:Any
Assigned to: CPU Architecture:Any

[1 Dec 2016 23:24] Knut Anders Hatlen
Description:
Prealloced_array takes a template argument called Has_trivial_constructor to determine if it needs to destroy elements when they are removed from the array or when the array is destroyed. This is easy to get wrong, which could lead either to memory leaks or to unnecessary work destroying elements that don't need destruction.

In C++11 we can instead use std::is_trivially_destructible to check if the elements need to be destroyed.

Adding the following assert to Prealloced_array

  static_assert(Has_trivial_destructor == std::is_trivially_destructible<Element_type>::value);

found that the following two Prealloced_array specializations have the wrong value for Has_trivial_destructor:

Show_var_array: Contains st_mysql_show_var, which is a trivially destructible POD type, but Has_trivial_destructor is false.

Json_path_clone::Path_leg_pointers: It is an array of pointers. Pointers don't need destruction, but Has_trivial_destructor is false.

How to repeat:
N/A
[6 Dec 2016 19:37] Paul DuBois
Posted by developer:
 
Fixed in 8.0.1.

Code cleanup. No changelog entry needed.