Sure, personally I don't like goto, but I saw the author uses it in this way. 

The free(NULL) issue I will do as your suggestions.