Index: /branches/eam_branches/ohana.20160226/src/relastro/include/relastro.h
===================================================================
--- /branches/eam_branches/ohana.20160226/src/relastro/include/relastro.h	(revision 39438)
+++ /branches/eam_branches/ohana.20160226/src/relastro/include/relastro.h	(revision 39439)
@@ -418,4 +418,5 @@
 
 void relastro_client_free ();
+void relastro_free ();
 
 GSCRegion    *find_regions        PROTO((Image *image, off_t Nimage, int *Nregions, GSCRegion *fullregion));
@@ -439,4 +440,5 @@
 void          initImageBins       PROTO((Catalog *catalog, int Ncatalog, int FULLINIT));
 void          initImages          PROTO((Image *input, off_t *line_number, off_t N));
+void          freeImages          PROTO(());
 void          initMosaicBins      PROTO((Catalog *catalog, int Ncatalog));
 void          initMosaicGrid      PROTO((Image *image, off_t Nimage));
@@ -554,4 +556,5 @@
 Mosaic *getmosaics (off_t *N);
 void initMosaics (Image *image, off_t Nimage);
+void freeMosaics ();
 StarData *getMosaicRaw (Catalog *catalog, int Ncatalog, off_t mos, off_t *Nstars);
 StarData *getMosaicRef (Catalog *catalog, int Ncatalog, off_t mos, off_t *Nstars);
@@ -590,4 +593,5 @@
 
 int initStarMaps ();
+void freeStarMaps ();
 int updateStarMaps(Catalog *catalog);
 int createStarMapPoints();
@@ -684,4 +688,5 @@
 AstromOffsetTable *get_astrom_table ();
 void put_astrom_table (AstromOffsetTable *myTable);
+void free_astrom_table ();
 
 int fit_map (AstromOffsetMap *map, StarData *raw, StarData *ref, int Npts);
Index: /branches/eam_branches/ohana.20160226/src/relastro/src/BootstrapOps.c
===================================================================
--- /branches/eam_branches/ohana.20160226/src/relastro/src/BootstrapOps.c	(revision 39438)
+++ /branches/eam_branches/ohana.20160226/src/relastro/src/BootstrapOps.c	(revision 39439)
@@ -98,4 +98,5 @@
       myAbort ("invalid option");
   }
+  free (values);
 
   return TRUE;
Index: /branches/eam_branches/ohana.20160226/src/relastro/src/BrightCatalog.c
===================================================================
--- /branches/eam_branches/ohana.20160226/src/relastro/src/BrightCatalog.c	(revision 39438)
+++ /branches/eam_branches/ohana.20160226/src/relastro/src/BrightCatalog.c	(revision 39439)
@@ -829,9 +829,20 @@
 int BrightCatalogSplitFree (CatalogSplitter *catalogs) {
 
-  free (catalogs->catIDs);
-  free (catalogs->NAVERAGE);
-  free (catalogs->NMEASURE);
-  free (catalogs->index);
-  free (catalogs);
+# if (0)
+  int i;
+
+  for (i = 0; i < catalogs->NCATALOG; i++) {
+    FREE (catalogs->catalog[i].average);
+    FREE (catalogs->catalog[i].secfilt);
+    FREE (catalogs->catalog[i].measureT);
+  }
+  FREE (catalogs->catalog);
+# endif
+
+  FREE (catalogs->catIDs);
+  FREE (catalogs->NAVERAGE);
+  FREE (catalogs->NMEASURE);
+  FREE (catalogs->index);
+  FREE (catalogs);
   return TRUE;
 }
Index: /branches/eam_branches/ohana.20160226/src/relastro/src/FitAstromOps.c
===================================================================
--- /branches/eam_branches/ohana.20160226/src/relastro/src/FitAstromOps.c	(revision 39438)
+++ /branches/eam_branches/ohana.20160226/src/relastro/src/FitAstromOps.c	(revision 39439)
@@ -297,4 +297,5 @@
     median = x[(int)(0.5*Npoints)];
   }
+  free (x);
 
   return median;
Index: /branches/eam_branches/ohana.20160226/src/relastro/src/ImageOps.c
===================================================================
--- /branches/eam_branches/ohana.20160226/src/relastro/src/ImageOps.c	(revision 39438)
+++ /branches/eam_branches/ohana.20160226/src/relastro/src/ImageOps.c	(revision 39439)
@@ -119,4 +119,20 @@
   }
 # endif
+}
+
+void freeImages () {
+
+  FREE (LineNumber);
+
+# if USE_IMAGE_ID
+  FREE (imageIDs);
+  FREE (imageIdx);
+  FREE (imageSeq);
+# else
+  FREE (start);
+  FREE (stop);
+# endif
+
+  free_astrom_table();
 }
 
@@ -196,15 +212,20 @@
 
   for (i = 0; i < Ncatalog; i++) {
-    free (MeasureToImage[i]);
-  }
-  free (MeasureToImage);
+    FREE (MeasureToImage[i]);
+  }
+  FREE (MeasureToImage);
   for (i = 0; i < Nimage; i++) {
-    if (ImageToCatalog[i]) { free (ImageToCatalog[i]); }
-    if (ImageToMeasure[i]) { free (ImageToMeasure[i]); }
-  }
-  free (ImageToCatalog);
-  free (ImageToMeasure);
-  free (N_onImage);
-  free (N_ONIMAGE);
+    FREE (ImageToCatalog[i]); 
+    FREE (ImageToMeasure[i]); 
+    FREE (catlist[i]); 
+  }
+  FREE (Ncatlist);
+  FREE (NCATLIST);
+  FREE (catlist);
+
+  FREE (ImageToCatalog);
+  FREE (ImageToMeasure);
+  FREE (N_onImage);
+  FREE (N_ONIMAGE);
 }
 
@@ -239,6 +260,9 @@
       name = GetPhotcodeNamebyCode (image[i].photcode);
       int showExample = (Nfew < 30);
-      if (showExample) fprintf (stderr, "image "OFF_T_FMT" (%d, %s) has "OFF_T_FMT" of %d measures (%s, %s) ",  i,  image[i].imageID, image[i].name, N_onImage[i], image[i].nstar,
-	       ohana_sec_to_date(image[i].tzero), name);
+      if (showExample) {
+	char *myDate = ohana_sec_to_date(image[i].tzero);
+	fprintf (stderr, "image "OFF_T_FMT" (%d, %s) has "OFF_T_FMT" of %d measures (%s, %s) ",  i,  image[i].imageID, image[i].name, N_onImage[i], image[i].nstar, myDate, name);
+	free (myDate);
+      }
       if (N_onImage[i] < 20) {
 	if (showExample) fprintf (stderr, "*");
Index: /branches/eam_branches/ohana.20160226/src/relastro/src/ImageTable.c
===================================================================
--- /branches/eam_branches/ohana.20160226/src/relastro/src/ImageTable.c	(revision 39438)
+++ /branches/eam_branches/ohana.20160226/src/relastro/src/ImageTable.c	(revision 39439)
@@ -33,4 +33,10 @@
   }
 
+  // gfits_db_free (&db);
+  gfits_free_header (&db.header);
+  gfits_free_matrix (&db.matrix);
+  gfits_free_header (&db.theader);
+  free (db.filename);
+
   *nimage = Nimage;
   return image;
@@ -61,4 +67,6 @@
   dvo_image_unlock (&db);
 
+  gfits_db_free (&db);
+
   return TRUE;
 }
Index: /branches/eam_branches/ohana.20160226/src/relastro/src/MosaicOps.c
===================================================================
--- /branches/eam_branches/ohana.20160226/src/relastro/src/MosaicOps.c	(revision 39438)
+++ /branches/eam_branches/ohana.20160226/src/relastro/src/MosaicOps.c	(revision 39439)
@@ -3,5 +3,5 @@
 // array of mosaic definition structures
 static off_t   Nmosaic;
-static Mosaic *mosaic;
+static Mosaic *mosaic = NULL;
 
 // list of all images associated with a mosaic
@@ -185,4 +185,21 @@
 }
 
+void freeMosaics () {
+
+  off_t i;
+
+  if (!mosaic) return;
+
+  for (i = 0; i < Nmosaic; i++) {
+    FREE (mosaic_own_images[i]);
+  }
+
+  FREE (mosaic);
+  FREE (Nmosaic_own_images);
+  FREE (Amosaic_own_images);
+  FREE (mosaic_own_images);
+  FREE (mosaic_for_images);
+}
+
 // return StarData values for detections in the specified image, converting coordinates from the
 // chip positions: X,Y -> L,M -> P,Q -> R,D
@@ -325,6 +342,10 @@
     }
     
+    free (addMosaic);
+
     host->Nimage += Nadd;
   }
+  free (mosaicUsed);
+
   return TRUE;
 }
Index: /branches/eam_branches/ohana.20160226/src/relastro/src/StarMaps.c
===================================================================
--- /branches/eam_branches/ohana.20160226/src/relastro/src/StarMaps.c	(revision 39438)
+++ /branches/eam_branches/ohana.20160226/src/relastro/src/StarMaps.c	(revision 39439)
@@ -25,5 +25,5 @@
 } StarMap;
 
-static StarMap     *starmap;         
+static StarMap *starmap = NULL; 
 // static int         Nstarmap;  -- is it always == Nimages?
 
@@ -55,4 +55,19 @@
 }
 
+void freeStarMaps () {
+
+  off_t i, Nimages;
+
+  getimages(&Nimages, NULL);
+
+  for (i = 0; i < Nimages; i++) {
+    FREE (starmap[i].points);
+    FREE (starmap[i].stars);
+  }
+
+  FREE (starmap);
+  return;
+}
+
 int updateStarMaps(Catalog *catalog) {
 
Index: /branches/eam_branches/ohana.20160226/src/relastro/src/args.c
===================================================================
--- /branches/eam_branches/ohana.20160226/src/relastro/src/args.c	(revision 39438)
+++ /branches/eam_branches/ohana.20160226/src/relastro/src/args.c	(revision 39439)
@@ -380,5 +380,4 @@
       snprintf (PHOTCODE_SKIP_LIST, Ntotal, "%s,%s", SuperCOSMOS_SKIP, RawSkip);
       free (RawSkip);
-      free (SuperCOSMOS_SKIP);
     } else {
       PHOTCODE_SKIP_LIST = RawSkip;
@@ -386,4 +385,5 @@
     remove_argument (N, &argc, argv);
   }
+  free (SuperCOSMOS_SKIP);
 
   VERBOSE = VERBOSE2 = FALSE;
@@ -570,4 +570,25 @@
   if (argc != 1) usage ();
   return TRUE;
+}
+
+void relastro_free () {
+  FREE (REGION_FILE);
+  FREE (IMAGE_TABLE);
+  FREE (LoopWeight2MASSstr);
+  FREE (LoopWeightTychostr);
+
+  FREE (PHOTCODE_SKIP_LIST);
+  FREE (PHOTCODE_KEEP_LIST);
+  FREE (PHOTCODE_RESET_LIST);
+  FREE (DCR_RED_COLOR_POS);
+  FREE (DCR_RED_COLOR_NEG);
+  FREE (DCR_BLUE_COLOR_POS);
+  FREE (DCR_BLUE_COLOR_NEG);
+
+  FREE (PHOTCODE_A_LIST);
+  FREE (PHOTCODE_B_LIST);
+  FREE (HIGH_SPEED_DIR);
+  FREE (BCATALOG);
+  FREE (HOSTDIR);
 }
 
Index: /branches/eam_branches/ohana.20160226/src/relastro/src/launch_region_hosts.c
===================================================================
--- /branches/eam_branches/ohana.20160226/src/relastro/src/launch_region_hosts.c	(revision 39438)
+++ /branches/eam_branches/ohana.20160226/src/relastro/src/launch_region_hosts.c	(revision 39439)
@@ -161,5 +161,8 @@
     fprintf (stderr, "command: %s\n", command);
     
-    if (PARALLEL_REGIONS_MANUAL) continue;
+    if (PARALLEL_REGIONS_MANUAL) { 
+      free (command);
+      continue;
+    }
 
     // launch the job, then wait for it to be done loading catalogs.  force the remote
@@ -180,4 +183,6 @@
     check_sync_file (syncfile, 1);
     free (syncfile);
+
+    free (command);
   }
 
Index: /branches/eam_branches/ohana.20160226/src/relastro/src/load_catalogs.c
===================================================================
--- /branches/eam_branches/ohana.20160226/src/relastro/src/load_catalogs.c	(revision 39438)
+++ /branches/eam_branches/ohana.20160226/src/relastro/src/load_catalogs.c	(revision 39439)
@@ -229,5 +229,8 @@
     fprintf (stderr, "command: %s\n", command);
 
-    if (PARALLEL_MANUAL) continue;
+    if (PARALLEL_MANUAL) {
+      free (command);
+      continue;
+    }
 
     if (PARALLEL_SERIAL) {
@@ -247,4 +250,5 @@
       table->hosts[i].pid = pid; // save for future reference
     }
+    free (command);
   }
 
@@ -294,6 +298,15 @@
   }
 
+  FreeHostTable (table);
+
   Catalog *catalog = catalogs->catalog;
   *Ncatalog = catalogs->Ncatalog;
+
+  // need to free the place-holder catalogs:
+  for (i = catalogs->Ncatalog; i < catalogs->NCATALOG; i++) {
+    free (catalogs->catalog[i].average);
+    free (catalogs->catalog[i].measureT);
+    free (catalogs->catalog[i].secfilt);
+  }
 
   int Nmeasure = 0;
Index: /branches/eam_branches/ohana.20160226/src/relastro/src/load_images.c
===================================================================
--- /branches/eam_branches/ohana.20160226/src/relastro/src/load_images.c	(revision 39438)
+++ /branches/eam_branches/ohana.20160226/src/relastro/src/load_images.c	(revision 39439)
@@ -102,2 +102,7 @@
 }
 
+void free_astrom_table () {
+  if (!table) return;
+  AstromOffsetTableFree (table);
+  free (table);
+}
Index: /branches/eam_branches/ohana.20160226/src/relastro/src/relastro.c
===================================================================
--- /branches/eam_branches/ohana.20160226/src/relastro/src/relastro.c	(revision 39438)
+++ /branches/eam_branches/ohana.20160226/src/relastro/src/relastro.c	(revision 39439)
@@ -7,7 +7,12 @@
   initialize (argc, argv);
 
-  SkyTable *sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, TRUE, SKY_DEPTH, VERBOSE);
-  SkyTableSetFilenames (sky, CATDIR, "cpt");
-  SkyList *skylist = SkyListByPatch (sky, -1, &UserPatch);
+  SkyTable *sky = NULL;
+  SkyList *skylist = NULL;
+
+  if ((RELASTRO_OP != OP_PARALLEL_IMAGES) && (RELASTRO_OP != OP_PARALLEL_REGIONS)) {
+    sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, TRUE, SKY_DEPTH, VERBOSE);
+    SkyTableSetFilenames (sky, CATDIR, "cpt");
+    skylist = SkyListByPatch (sky, -1, &UserPatch);
+  }
 
   switch (RELASTRO_OP) {
@@ -15,4 +20,6 @@
       /* the object analysis is a separate process iterating over catalogs */
       relastro_objects (skylist, 0, NULL);
+      ohana_memcheck (VERBOSE);
+      ohana_memdump (VERBOSE);
       exit (0);
 
@@ -33,4 +40,18 @@
     case OP_IMAGES:
       relastro_images (skylist);
+
+      relastro_free ();
+      FREE(photcodesKeep);
+      FREE(photcodesSkip);  
+      FREE(photcodesReset); 
+      FREE(photcodesGroupA);
+      FREE(photcodesGroupB);
+
+      SkyTableFree (sky);
+      SkyListFree(skylist);
+      FreePhotcodeTable();
+
+      ohana_memcheck (VERBOSE);
+      ohana_memdump (VERBOSE);
       exit (0);
 
@@ -55,4 +76,6 @@
       // iterate over catalogs to make detection coordinates consistant
       UpdateObjectOffsets (skylist, 0, NULL);
+      ohana_memcheck (VERBOSE);
+      ohana_memdump (VERBOSE);
       exit (0);
 
Index: /branches/eam_branches/ohana.20160226/src/relastro/src/relastro_images.c
===================================================================
--- /branches/eam_branches/ohana.20160226/src/relastro/src/relastro_images.c	(revision 39438)
+++ /branches/eam_branches/ohana.20160226/src/relastro/src/relastro_images.c	(revision 39439)
@@ -98,8 +98,19 @@
   }
 
-  if (!UPDATE) exit (0);
+  if (!UPDATE) { 
+    freeStarMaps();
+    gfits_db_free (&db);
+    ohana_memcheck (VERBOSE);
+    ohana_memdump (VERBOSE);
+    exit (0);
+  }
 
   // free the image / measurement pointers
-  freeImageBins (1);
+  freeImageBins (Ncatalog);
+  for (i = 0; i < Ncatalog; i++) {
+    dvo_catalog_free (&catalog[i]);
+  }
+  free (catalog);
+  freeMosaics ();
 
   // If we did NOT use all images, then we applied the measured corrections to a subset of
@@ -110,4 +121,5 @@
     reload_images (&db);
   }
+  freeStarMaps();
     
   if (PARALLEL) {
@@ -121,4 +133,6 @@
     }
     dvo_image_unlock (&db); 
+    gfits_db_free (&db);
+    freeImages();
   }
 
@@ -146,6 +160,8 @@
     }
     dvo_image_unlock (&db); 
+    gfits_db_free (&db);
+    freeImages();
   }
 
-  exit (0);
+  return TRUE;
 }
Index: /branches/eam_branches/ohana.20160226/src/relastro/src/relastro_parallel_images.c
===================================================================
--- /branches/eam_branches/ohana.20160226/src/relastro/src/relastro_parallel_images.c	(revision 39438)
+++ /branches/eam_branches/ohana.20160226/src/relastro/src/relastro_parallel_images.c	(revision 39439)
@@ -181,4 +181,32 @@
   LOGRTIME("share image pos loop %d on %s, host %d: %f sec\n", -1, myHostName, REGION_HOST_ID, dtime);
 
+  // free the image / measurement pointers
+  freeImageBins (Ncatalog);
+  for (i = 0; i < Ncatalog; i++) {
+    dvo_catalog_free (&catalog[i]);
+  }
+  free (catalog);
+  freeMosaics ();
+
+  freeStarMaps();
+
+  freeImages();
+  free (image);
+
+  relastro_free ();
+  FREE(photcodesKeep);
+  FREE(photcodesSkip);  
+  FREE(photcodesReset); 
+  FREE(photcodesGroupA);
+  FREE(photcodesGroupB);
+  
+  SkyTableFree (sky);
+  SkyListFree(skylist);
+  FreePhotcodeTable();
+  
+  FreeRegionHostTable (regionHosts);
+
+  ohana_memcheck (VERBOSE);
+  ohana_memdump (VERBOSE);
   exit (0);
 }
Index: /branches/eam_branches/ohana.20160226/src/relastro/src/relastro_parallel_regions.c
===================================================================
--- /branches/eam_branches/ohana.20160226/src/relastro/src/relastro_parallel_regions.c	(revision 39438)
+++ /branches/eam_branches/ohana.20160226/src/relastro/src/relastro_parallel_regions.c	(revision 39439)
@@ -83,5 +83,27 @@
   }
 
+// testjump:
+
   MARKTIME ("finished relastro -parallel-regions: %f sec total\n", dtime);
+  
+  gfits_db_free (&db);
+  freeImages();
+  freeMosaics ();
+
+  relastro_free ();
+  FREE(photcodesKeep);
+  FREE(photcodesSkip);  
+  FREE(photcodesReset); 
+  FREE(photcodesGroupA);
+  FREE(photcodesGroupB);
+  
+  SkyTableFree (sky);
+  SkyListFree(skylist);
+  FreePhotcodeTable();
+  
+  FreeRegionHostTable (regionHosts);
+
+  ohana_memcheck (VERBOSE);
+  ohana_memdump (VERBOSE);
 
   exit (0);
Index: /branches/eam_branches/ohana.20160226/src/relastro/src/share_images_pos.c
===================================================================
--- /branches/eam_branches/ohana.20160226/src/relastro/src/share_images_pos.c	(revision 39438)
+++ /branches/eam_branches/ohana.20160226/src/relastro/src/share_images_pos.c	(revision 39439)
@@ -141,4 +141,5 @@
 
     AstromOffsetTableFree(table);
+    free (table);
     LOGRTIME("image_maps_free host %d loop %d on %s, host %d: %f sec\n", i, nloop, myHostName, REGION_HOST_ID, dtime);
   }
