IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 38502


Ignore:
Timestamp:
Jun 19, 2015, 3:11:47 PM (11 years ago)
Author:
eugene
Message:

do a better job of freeing memory

Location:
branches/eam_branches/ipp-20150616/Ohana/src/dvomerge
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20150616/Ohana/src/dvomerge/include/dvomerge.h

    r38497 r38502  
    116116void       dvomerge_help          PROTO((int argc, char **argv));
    117117int        dvomerge_args          PROTO((int *argc, char **argv));
     118void       dvomerge_args_free     PROTO((void));
    118119
    119120void       dvomerge_client_usage  PROTO((void));
     
    175176int        dvo_update_image_IDs   PROTO((IDmapType *IDmap, Catalog *catalog));
    176177void       dvo_image_map_free     PROTO((IDmapType *IDmap));
     178void       dvo_image_map_init     PROTO((IDmapType *IDmap));
    177179
    178180// dvorepair prototypes
     
    213215int dmhObjectCheck (dmhObject *history, dmhObjectStats *inStats);
    214216dmhObject *dmhObjectRead (char *filename);
     217dmhObject *dmhObjectAlloc (void);
     218void dmhObjectFree (dmhObject *history);
    215219
    216220void dmhObjectStatsFree (dmhObjectStats *stats);
     
    218222
    219223int dmhImageAdd (FITS_DB *db, dmhImage *history, char *dbID);
    220 dmhImage *dmhImageRead (FITS_DB *db) ;
     224dmhImage *dmhImageRead (FITS_DB *db);
    221225int dmhImageCheck (dmhImage *history, char *dbID);
     226void dmhImageFree(dmhImage *history);
    222227
    223228char *dmhImageReadID (FITS_DB *db);
  • branches/eam_branches/ipp-20150616/Ohana/src/dvomerge/src/ConfigInit.c

    r27435 r38502  
    4747  VERBOSE = TRUE;
    4848
     49  FreeConfigFile();
    4950  free (config);
    5051  free (file);
  • branches/eam_branches/ipp-20150616/Ohana/src/dvomerge/src/args.c

    r38468 r38502  
    66  int N;
    77
     8  HOSTDIR = NULL;
     9  SINGLE_CPT = NULL;
     10
    811  /* extra error messages */
    912  VERBOSE = FALSE;
     
    5356
    5457  /* use a different photcode file to define mean values */
     58  ALTERNATE_PHOTCODE_FILE = NULL;
    5559  if ((N = get_argument (*argc, argv, "-photcode-file"))) {
    5660    remove_argument (N, argc, argv);
     
    156160}
    157161
     162void dvomerge_args_free (void) {
     163  FREE (HOSTDIR);
     164  FREE (ALTERNATE_PHOTCODE_FILE);
     165  FREE (UPDATE_CATFORMAT);
     166  FREE (UPDATE_CATCOMPRESS);
     167  FREE (SINGLE_CPT);
     168}
     169
    158170/*** check for command line options ***/
    159171int dvomerge_client_args (int *argc, char **argv) {
  • branches/eam_branches/ipp-20150616/Ohana/src/dvomerge/src/dvo_image_merge_dbs.c

    r38497 r38502  
    66off_t getTgtIndex (e_time start, e_time stop, short photcode, off_t *TgtIndex, e_time *TgtTimes, short *TgtCodes, off_t NimagesTgt);
    77
     8void dvo_image_map_init (IDmapType *IDmap) {
     9  // we don't own the IDmap, just the elements
     10  IDmap->old = NULL;
     11  IDmap->new = NULL;
     12  IDmap->notFound = NULL;
     13  IDmap->Nmap = 0;
     14}
     15
    816void dvo_image_map_free (IDmapType *IDmap) {
    917  // we don't own the IDmap, just the elements
    10   free (IDmap->old);
    11   free (IDmap->old);
    12   free (IDmap->notFound);
     18  FREE (IDmap->old);
     19  FREE (IDmap->new);
     20  FREE (IDmap->notFound);
    1321}
    1422
  • branches/eam_branches/ipp-20150616/Ohana/src/dvomerge/src/dvomerge.c

    r35765 r38502  
    77  ConfigInit (&argc, argv);
    88  dvomerge_args (&argc, argv);
     9
     10  if ((argc < 4) || (argc > 6)) dvomerge_usage();
    911
    1012  if (argc == 6) {
     
    3840    }
    3941  }
    40   dvomerge_usage();
    41   exit (2); // cannot reach here.
     42  dvomerge_args_free ();
     43  ohana_memcheck (TRUE);
     44  ohana_memdump (TRUE);
     45  exit (0);
    4246}
    4347
  • branches/eam_branches/ipp-20150616/Ohana/src/dvomerge/src/dvomergeHistory.c

    r34578 r38502  
    2828  char *ID = strcreate (dbID);
    2929  return ID;
     30}
     31
     32void dmhImageFree(dmhImage *history) {
     33  if (!history) return;
     34 
     35  int i;
     36  for (i = 0; i < history->Nmerge; i++) {
     37    FREE (history->IDs[i]);
     38  }
     39  FREE (history->IDs);
     40  FREE (history);
    3041}
    3142
     
    125136}
    126137
     138dmhObject *dmhObjectAlloc (void) {
     139
     140  dmhObject *history = NULL;
     141  ALLOCATE (history, dmhObject, 1);
     142  history->Nmerge = 0;
     143 
     144  // ALLOCATE full list
     145  ALLOCATE (history->size, off_t,  history->Nmerge);
     146  ALLOCATE (history->time, time_t, history->Nmerge);
     147  ALLOCATE (history->date, char *, history->Nmerge);
     148  return history;
     149}
     150
     151void dmhObjectFree (dmhObject *history) {
     152  if (!history) return;
     153
     154  FREE (history->size);
     155  FREE (history->time);
     156
     157  if (history->date) {
     158    int i;
     159    for (i = 0; i < history->Nmerge; i++) {
     160      FREE (history->date[i]);
     161    }
     162  }
     163  FREE (history->date);
     164  FREE (history);
     165  return;
     166}
     167
    127168// read the array of merged history information from this file's header
    128169dmhObject *dmhObjectRead (char *filename) {
     
    133174  if (stat_result) {
    134175    if (errno == ENOENT) {
    135       dmhObject *history = NULL;
    136       ALLOCATE (history, dmhObject, 1);
    137       history->Nmerge = 0;
    138    
    139       // ALLOCATE full list
    140       ALLOCATE (history->size, off_t,  history->Nmerge);
    141       ALLOCATE (history->time, time_t, history->Nmerge);
    142       ALLOCATE (history->date, char *, history->Nmerge);
     176      dmhObject *history = dmhObjectAlloc();
    143177      return history;
    144178    }
     
    162196  fclose (fout);
    163197
    164   dmhObject *history = NULL;
    165   ALLOCATE (history, dmhObject, 1);
     198  dmhObject *history = dmhObjectAlloc();
    166199
    167200  int status = gfits_scan (&outheader, "NMERGE", "%d", 1, &history->Nmerge);     
     
    171204
    172205  // ALLOCATE full list
    173   ALLOCATE (history->size, off_t,  history->Nmerge);
    174   ALLOCATE (history->time, time_t, history->Nmerge);
    175   ALLOCATE (history->date, char *, history->Nmerge);
     206  REALLOCATE (history->size, off_t,  history->Nmerge);
     207  REALLOCATE (history->time, time_t, history->Nmerge);
     208  REALLOCATE (history->date, char *, history->Nmerge);
    176209
    177210  int i;
     
    199232    history->time[i] = ohana_date_to_sec (date);
    200233  }
     234  gfits_free_header (&outheader);
    201235  return history;
    202236}
     
    239273  history->size[last] = inStats->size;
    240274  history->time[last] = inStats->time;
    241   history->date[last] = inStats->date;
     275  history->date[last] = strcreate (inStats->date);
    242276
    243277  char name[16];
     
    280314  int i;
    281315  for (i = 0; i < N; i++) {
    282     if (outstat[i].history)  { free (outstat[i].history); }
     316    if (outstat[i].history)  { dmhObjectFree (outstat[i].history); }
    283317    if (outstat[i].filename) { free (outstat[i].filename); }
    284318  }
  • branches/eam_branches/ipp-20150616/Ohana/src/dvomerge/src/dvomergeImageIDs.c

    r38497 r38502  
    6464    dvo_image_match_dbs(IDmap, &outDB, &inDB);
    6565    dvo_image_unlock (&outDB); // unlock output
     66
     67    gfits_db_free (&inDB);
     68    gfits_db_free (&outDB);
     69    dmhImageFree (history);
     70    FREE (indbID);
    6671    return TRUE;
    6772  }
     
    8186  dvo_image_unlock (&outDB); // unlock output
    8287
    83   gfits_db_free (inDB);
    84   gfits_db_free (outDB);
     88  gfits_db_free (&inDB);
     89  gfits_db_free (&outDB);
     90
     91  dmhImageFree (history);
     92  FREE (indbID);
    8593
    8694  return TRUE;
     
    139147  dvo_image_match_dbs(IDmap, &outDB, &inDB);
    140148
    141   gfits_db_free (inDB);
    142   gfits_db_free (outDB);
     149  gfits_db_free (&inDB);
     150  gfits_db_free (&outDB);
    143151
    144152  return TRUE;
  • branches/eam_branches/ipp-20150616/Ohana/src/dvomerge/src/dvomergeUpdate.c

    r38497 r38502  
    88  char filename[256], *input, *output;
    99  IDmapType IDmap;
    10   PhotCodeData *inputPhotcodes;
    11   PhotCodeData *outputPhotcodes;
    1210  int *secfiltMap = NULL;
    1311  int NsecfiltInput, NsecfiltOutput;
    1412
    1513  INITTIME;
     14
     15  dvo_image_map_init (&IDmap);
    1616
    1717  CONTINUE = FALSE;
     
    3434    exit (1);
    3535  }
     36
     37  PhotCodeData *inputPhotcodes  = NULL;
     38  PhotCodeData *outputPhotcodes = NULL;
    3639
    3740  SetPhotcodeTable(NULL);
     
    112115
    113116  int status = dvomergeUpdate_catalogs (input, output, outsky, inlist, NsecfiltInput, NsecfiltOutput, &IDmap, secfiltMap);
    114   dvo_image_map_free (&IDmap);
    115117
    116118  // save the output sky table copy
     
    121123    exit (1);
    122124  }
     125  FREE (skyfile);
    123126
    124   ohana_memcheck (TRUE);
     127  SkyTableFree (insky);
     128  SkyTableFree (outsky);
     129  SkyListFree (inlist);
     130
     131  FREE (secfiltMap);
     132  dvo_image_map_free (&IDmap);
     133  if (outputPhotcodes != inputPhotcodes) { FreePhotcodeData (outputPhotcodes); }
     134  FreePhotcodeData (inputPhotcodes);
     135  FreePhotcodeTable ();
    125136
    126137  if (!status) {
     
    130141
    131142  MARKTIME ("SUCCESS: elapsed time %9.4f sec\n", dtime);
    132   exit (0);
     143  return TRUE;
    133144}
Note: See TracChangeset for help on using the changeset viewer.