From 0b737248c3857966a57cf0af14bd9cf81e9292f7 Mon Sep 17 00:00:00 2001 From: eclark Date: Tue, 10 Dec 2013 00:55:39 +0000 Subject: [PATCH] HBASE-10043 Fix Potential Resouce Leak in MultiTableInputFormatBase git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1549726 13f79535-47bb-0310-9956-ffa450edef68 --- .../mapreduce/MultiTableInputFormatBase.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/MultiTableInputFormatBase.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/MultiTableInputFormatBase.java index f30178998ab..9a6b77abec8 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/MultiTableInputFormatBase.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/MultiTableInputFormatBase.java @@ -83,15 +83,24 @@ public abstract class MultiTableInputFormatBase extends new HTable(context.getConfiguration(), tSplit.getTableName()); TableRecordReader trr = this.tableRecordReader; - // if no table record reader was provided use default - if (trr == null) { - trr = new TableRecordReader(); + + try { + // if no table record reader was provided use default + if (trr == null) { + trr = new TableRecordReader(); + } + Scan sc = tSplit.getScan(); + sc.setStartRow(tSplit.getStartRow()); + sc.setStopRow(tSplit.getEndRow()); + trr.setScan(sc); + trr.setHTable(table); + } catch (IOException ioe) { + // If there is an exception make sure that all + // resources are closed and released. + table.close(); + trr.close(); + throw ioe; } - Scan sc = tSplit.getScan(); - sc.setStartRow(tSplit.getStartRow()); - sc.setStopRow(tSplit.getEndRow()); - trr.setScan(sc); - trr.setHTable(table); return trr; }