commit-reach: fix memory and flag leaks