if ((p = malloc(..)) == NULL) goto END;
if ((fp = fopen(..)) == NULL) goto END;
if (fwrite(..)) == -1) goto END;
END:
fclose(fp);
free(p);
return;

で、どう?カコイイくは無いと思うが。
C++でならtry...catchがあるけど、ここCスレだし。