StateDB: Free locale string also if attribs are invalid.

This fixes Coverity CID 12898
stateDB: Close the file descriptor even if stat failed.

This fixes Coverity CID 12897