Fix use-after-free in submodule reload

If the first call to release a no-longer-existent submodule freed
the object, the check if a second is needed would dereference the
data that was just freed.
Fix memory leak of submodule branch name
Fix memory leak of test repository object
Merge pull request #2212 from libgit2/rb/submodule-use-after-free

Fix use-after-free in submodule reload code and other memory leaks
Introduce core.safecrlf handling