Repair refcounting on error return from type_set_bases.

Include a test case that failed for one of my efforts to repair this.
2 files changed