void foo() { char *p = malloc(...); defer free(p); ... { FILE *p = fopen(...); defer fclose(p); ... } return; }