SPARK-1482: Fix potential resource leaks in saveAsHadoopDataset and save...

...AsNewAPIHadoopDataset

JIRA: https://issues.apache.org/jira/browse/SPARK-1482