Hello everyone,


Should I delete memory pointed by pointer a if there is bad_alloc when allocating memory in memory pointed by pointer b? I am not sure whether there will be memory leak if I do not delete a.

Code:
try {
    a = new int [N];
    b = new int [M];
} catch (bad_alloc)
{
    // if a success, but b fail, should we try to delete[] a here to avoid memory leak?

}

thanks in advance,
George