Fix missing check on nc_type and fix memory leaks in error handling
Fix missing check on nc_type and fix memory leaks in error handling

stcorp/coda,stcorp/coda,stcorp/coda,stcorp/coda,stcorp/coda,stcorp/coda,stcorp/coda