Fix mem leak and mismatched new/delete