fixed minor lifecycle bug in LSM search cursors--properly close even if not used for a search

git-svn-id: https://hyracks.googlecode.com/svn/branches/hyracks_lsm_tree@1899 123451ca-8445-de46-9d55-352943316053
diff --git a/hyracks-storage-am-lsm-common/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/common/impls/LSMTreeSearchCursor.java b/hyracks-storage-am-lsm-common/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/common/impls/LSMTreeSearchCursor.java
index 4306527..0d513af 100644
--- a/hyracks-storage-am-lsm-common/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/common/impls/LSMTreeSearchCursor.java
+++ b/hyracks-storage-am-lsm-common/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/common/impls/LSMTreeSearchCursor.java
@@ -99,14 +99,16 @@
 
     @Override
     public void close() throws HyracksDataException {
-        try {
-            outputPriorityQueue.clear();
-            for (int i = 0; i < rangeCursors.length; i++) {
-                rangeCursors[i].close();
+        if (lsmHarness != null) {
+            try {
+                outputPriorityQueue.clear();
+                for (int i = 0; i < rangeCursors.length; i++) {
+                    rangeCursors[i].close();
+                }
+                rangeCursors = null;
+            } finally {
+                lsmHarness.closeSearchCursor(searcherRefCount, includeMemComponent);
             }
-            rangeCursors = null;
-        } finally {
-            lsmHarness.closeSearchCursor(searcherRefCount, includeMemComponent);
         }
     }
 
@@ -140,7 +142,7 @@
     protected boolean isDeleted(PriorityQueueElement checkElement) throws HyracksDataException, IndexException {
         return ((ILSMTreeTupleReference) checkElement.getTuple()).isAntimatter();
     }
-    
+
     protected void checkPriorityQueue() throws HyracksDataException, IndexException {
         while (!outputPriorityQueue.isEmpty() || needPush == true) {
             if (!outputPriorityQueue.isEmpty()) {