Fix multiple ASAN related crashes