Coverity fixes

This fixes a few problems pointed out by the coverity scan including missing checks for OOM, not checking error codes, memory leaks etc.

This doesn't fix nearly all of the problems but does address lots of the low hanging fruit.
This would return `((git_filter *) -1)` which is not a value that has any meaning wrt OOM. We should do something like

    if (f == NULL)
        return NULL;

Longer term maybe change it to have an int return value.