Casting the return value of malloc will save you from coding mistakes along the lines of:

#define ENTRIES 10
int i;
double **val;

val = (double **) malloc(ENTRIES*sizeof(double *));
for(i = 0 ; i < ENTRIES ; i++)
        val = (double *) malloc(sizeof(double)); /* OOOPS */
Blowing away previously allocated pointers is a bad idea. In the above code, the compiler should alert you of the type mismatch and error out. Leave the cast out, and it will compile with no trouble and you'll be chasing the crazy segmentation fault for the next 30 minutes.