Fix bugs reported by Coverity:

1260223
1260224

One potential memory leak, and one redundant NULL check.