From 78936db663f1cbb88e6e20892e66a5c6957042bf Mon Sep 17 00:00:00 2001 From: Elliott Neil Clark Date: Mon, 9 Dec 2013 10:54:51 -0800 Subject: [PATCH] HBASE-10043 Fix Potential Resouce Leak in MultiTableInputFormatBase --- .../hbase/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 f301789..9a6b77a 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; } -- 1.8.4.3