Index: trunk/Ohana/src/opihi/dvo/avmatch.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/avmatch.c	(revision 27594)
+++ trunk/Ohana/src/opihi/dvo/avmatch.c	(revision 27610)
@@ -83,4 +83,11 @@
     if ((vec[i] = SelectVector (name, ANYVECTOR, TRUE)) == NULL) goto escape;
     ResetVector (vec[i], fields[i].type, NPTS);
+    for (n = 0; n < vec[i][0].Nelements; n++) {
+      if (vec[i][0].type == OPIHI_FLT) {
+	vec[i][0].elements.Flt[n] = NAN;
+      } else {
+	vec[i][0].elements.Int[n] = 0; // or NAN_INT?
+      }
+    }
   }
   ALLOCATE (index, off_t, NPTS);
@@ -103,4 +110,8 @@
     }
     dvo_catalog_unlock (&catalog);  /// we can unlock here since this is read-only (do not block other access)
+    if (catalog.Naverage == 0) {
+      dvo_catalog_free (&catalog);
+      continue;
+    }
 
     find_matches_by_vectors (skylist[0].regions[i], &catalog, RAvec, DECvec, RADIUS, index);
@@ -111,14 +122,6 @@
 
       if (Ncat == -1) continue;
-      if (Ncat == -2) {
-	for (n = 0; n < Nfields; n++) {
-	  if (vec[n][0].type == OPIHI_FLT) {
-	    vec[n][0].elements.Flt[Npts] = NAN;
-	  } else {
-	    vec[n][0].elements.Int[Npts] = 0; // or NAN_INT?
-	  }
-	}
-	continue;
-      }
+      if (Ncat == -2) continue;
+
       // XXX set a 'found' vector to double check we catch everything?
       m = catalog.average[Ncat].measureOffset;
@@ -148,5 +151,4 @@
   dbFreeFields (fields, Nfields);
   SkyListFree (skylist);
-  dvo_catalog_free (&catalog);
   return (TRUE);
 
@@ -156,5 +158,4 @@
   dbFreeFields (fields, Nfields);
   SkyListFree (skylist);
-  dvo_catalog_free (&catalog);
   return (FALSE);
 
