Move the const_cast from assignment to free

The problem is that some of the times the pointers hold values
to const tables and some others hold values to dynamic memory.

Instead of const_casting the const tables when needed and holding a non
const pointer, we hold a const pointer and only const cast on free if
needed
6 jobs for const_cast_switch in 10 minutes and 23 seconds (queued for 1 second)
Status Job ID Name Coverage
  Build
passed #676211
build

00:10:23

passed #676216
build_android

00:00:56

passed #676212
build_clang_libcpp

00:10:18

passed #676215
build_clazy

00:02:38

passed #676214
build_mingw64_fedora

00:02:43

passed #676213
build_ubuntu_16_04

00:08:38