For two dimensional array allocation in C/C++ , the very common code is : 

```
const int array_size = .. ;
array = (int**) malloc(array_size);
for (int c=0;c<array_size;c++)
    array[c] = (int*) malloc(other_size);

```

But I think we should be writing this:

```
const int array_size = .. ;
array = (int*) malloc(array_size);
int c;
bool free_array = false;
for (c=0;c<array_size;c++) {
    array[c] = (int*) malloc(other_size);
    if(array[c] == NULL){
        free_array = true;
        break;
    }
}
if(free_array) {
   for (int c1=0;c1<c;c1++)
     free(array[c1]);
}

```

to make sure that if one allocation failed we will free the previously allocated memory.

Am I correct?

Note : in C++ there is an alternative safe method with smart pointers and STL containers, but lets talk about raw pointers here or about C pointers.