Output errors after generating, if there are any
Close some memory leaks, reduce a scope (thx, cppcheck!)