Free resources and error cases; re-indent a curly brace while here.

CID:		1199366
Found with:	Coverity Prevent(tm)
MFC after:	1 week