[clang-analyzer] Fix mismatched new[] and free()
[clang-analyzer] Fix use after free
[clang-analyzer] Fix possible nullptr dereference