Start removing if (foo) free(foo);

free(NULL) is declared a no-op.