IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6342


Ignore:
Timestamp:
Feb 7, 2006, 11:18:31 AM (20 years ago)
Author:
Paul Price
Message:

Squashing memory leaks

Location:
branches/eam_rel9_p0/psModules/src/astrom
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_rel9_p0/psModules/src/astrom/pmChipMosaic.c

    r6145 r6342  
    66#include "pmChipMosaic.h"
    77
    8 #define MEM_LEAKS 1
     8#define MEM_LEAKS 0
    99
    1010// Compare a value with a maximum and minimum
     
    156156            continue;
    157157        }
     158
     159        psMetadataPrint(cell->concepts, 10);
     160
    158161        nCells++;
    159162        gain       += psMetadataLookupF32(NULL, cell->concepts, "CELL.GAIN");
     
    266269
    267270        // The images to put into the mosaic
    268         images->data[i]  = readout->image;
    269         weights->data[i] = readout->weight;
    270         masks->data[i]   = readout->mask;
     271        images->data[i]  = psMemIncrRefCounter(readout->image);
     272        weights->data[i] = psMemIncrRefCounter(readout->weight);
     273        masks->data[i]   = psMemIncrRefCounter(readout->mask);
    271274    }
    272275    // Mosaic the images together and we're done
     
    311314
    312315    // Chop off all the component cells, and put in a new one
    313     #ifndef MEM_LEAKS
     316    #if !MEM_LEAKS
    314317    pmChipFreeCells(chip);
    315318    #else
     
    321324    cellConcepts(cell, cells, xBinChip, yBinChip);
    322325
    323     #if 1
     326    #if 0
    324327    // XXX For the sake of getting something working, I am not going to bother with sorting out where
    325328    // the double free is coming from.  I'm going to drop the pointers on the array and create a memory
    326329    // leak.  We can clean this up later, when we're not under as much pressure.
    327     #else
    328 
    329330    psArrayElementsFree(chip->cells);
    330331    chip->cells->n = 0;
     
    337338    // Want the readouts to contain a subimage, but that subimage is the whole image.
    338339    // This preserves the relationship there was before, where freeing the parent frees the child.
    339     readout->image = psMemIncrRefCounter(psImageSubset(image, entire));
    340     readout->weight = psMemIncrRefCounter(psImageSubset(weight, entire));
    341     readout->mask = psMemIncrRefCounter(psImageSubset(mask, entire));
     340    readout->image = psImageSubset(image, entire);
     341    readout->weight = psImageSubset(weight, entire);
     342    readout->mask = psImageSubset(mask, entire);
    342343    psFree(readout);
    343344
  • branches/eam_rel9_p0/psModules/src/astrom/pmConcepts.c

    r6124 r6342  
    1111#include "psAdditionals.h"
    1212
     13static bool conceptsInitialised = false;// Have concepts been read?
    1314static psMetadata *conceptsFPA = NULL;  // Known concepts for FPA
    1415static psMetadata *conceptsChip = NULL; // Known concepts for chip
     
    2930    psMemSetDeallocator(spec, (psFreeFunc)conceptSpecFree);
    3031
    31     spec->blank = blank;
     32    spec->blank = psMemIncrRefCounter(blank);
    3233    spec->read = read;
    3334    spec->write = write;
     
    4445{
    4546    assert(blank);
    46     pmConceptsInit();
     47    if (!conceptsInitialised) {
     48        pmConceptsInit();
     49    }
    4750
    4851    pmConceptSpec *spec = pmConceptSpecAlloc(blank, read, write); // The concept specification
     
    6669    psMetadataAdd(*target, PS_LIST_TAIL, blank->name, PS_DATA_UNKNOWN | PS_META_REPLACE,
    6770                  "Concepts specification", spec);
     71    psFree(spec);                       // Drop reference
    6872
    6973    return true;
     
    105109                         )
    106110{
    107     pmConceptsInit();
     111    if (!conceptsInitialised) {
     112        pmConceptsInit();
     113    }
    108114    psMetadataIterator *specsIter = psMetadataIteratorAlloc(*specs, PS_LIST_HEAD, NULL); // Iterator on specs
    109115    psMetadataItem *specItem = NULL;    // Item from the specs metadata
    110116    while ((specItem = psMetadataGetAndIncrement(specsIter))) {
     117        psTrace(__func__, 9, "Blanking %s...\n", specItem->name);
    111118        pmConceptSpec *spec = specItem->data.V; // The specification
    112119        psMetadataItem *blank = spec->blank; // The concept
     
    127134                        )
    128135{
    129     pmConceptsInit();
     136    if (!conceptsInitialised) {
     137        pmConceptsInit();
     138    }
    130139    psMetadataIterator *specsIter = psMetadataIteratorAlloc(*specs, PS_LIST_HEAD, NULL); // Iterator on specs
    131140    psMetadataItem *specItem = NULL;    // Item from the specs metadata
     
    157166                         )
    158167{
    159     pmConceptsInit();
     168    if (!conceptsInitialised) {
     169        pmConceptsInit();
     170    }
    160171    if (! fpa->camera) {
    161172        return false;
     
    282293
    283294        // FPA.NAME
    284         pmConceptRegister(psMetadataItemAllocStr("FPA.NAME", "Name of FPA", ""), NULL, NULL,
    285                           PM_CONCEPT_LEVEL_FPA);
     295        {
     296            psMetadataItem *fpaName = psMetadataItemAllocStr("FPA.NAME", "Name of FPA", "");
     297            pmConceptRegister(fpaName, NULL, NULL, PM_CONCEPT_LEVEL_FPA);
     298            psFree(fpaName);
     299        }
    286300
    287301        // FPA.AIRMASS
    288         pmConceptRegister(psMetadataItemAllocF32("FPA.AIRMASS", "Airmass at boresight", 0.0), NULL, NULL,
    289                           PM_CONCEPT_LEVEL_FPA);
     302        {
     303            psMetadataItem *fpaAirmass = psMetadataItemAllocF32("FPA.AIRMASS", "Airmass at boresight", 0.0);
     304            pmConceptRegister(fpaAirmass, NULL, NULL, PM_CONCEPT_LEVEL_FPA);
     305            psFree(fpaAirmass);
     306        }
    290307
    291308        // FPA.FILTER
    292         pmConceptRegister(psMetadataItemAllocStr("FPA.FILTER", "Filter used", ""), NULL, NULL,
    293                           PM_CONCEPT_LEVEL_FPA);
     309        {
     310            psMetadataItem *fpaFilter = psMetadataItemAllocStr("FPA.FILTER", "Filter used", "");
     311            pmConceptRegister(fpaFilter, NULL, NULL, PM_CONCEPT_LEVEL_FPA);
     312            psFree(fpaFilter);
     313        }
    294314
    295315        // FPA.POSANGLE
    296         pmConceptRegister(psMetadataItemAllocF32("FPA.POSANGLE", "Position angle of instrument", 0.0), NULL,
    297                           NULL, PM_CONCEPT_LEVEL_FPA);
     316        {
     317            psMetadataItem *fpaPosangle = psMetadataItemAllocF32("FPA.POSANGLE",
     318                                          "Position angle of instrument", 0.0);
     319            pmConceptRegister(fpaPosangle, NULL, NULL, PM_CONCEPT_LEVEL_FPA);
     320            psFree(fpaPosangle);
     321        }
    298322
    299323        // FPA.RADECSYS
    300         pmConceptRegister(psMetadataItemAllocStr("FPA.RADECSYS", "Celestial coordinate system", ""), NULL,
    301                           NULL, PM_CONCEPT_LEVEL_FPA);
     324        {
     325            psMetadataItem *fpaRadecsys = psMetadataItemAllocStr("FPA.RADECSYS",
     326                                          "Celestial coordinate system", "");
     327            pmConceptRegister(fpaRadecsys, NULL, NULL, PM_CONCEPT_LEVEL_FPA);
     328            psFree(fpaRadecsys);
     329        }
    302330
    303331        // FPA.RA
    304         pmConceptRegister(psMetadataItemAllocF64("FPA.RA", "Right Ascension of boresight", NAN),
    305                           (pmConceptReadFunc)pmConceptRead_FPA_RA, (pmConceptWriteFunc)pmConceptWrite_FPA_RA,
    306                           PM_CONCEPT_LEVEL_FPA);
     332        {
     333            psMetadataItem *fpaRa = psMetadataItemAllocF64("FPA.RA", "Right Ascension of boresight", NAN);
     334            pmConceptRegister(fpaRa, (pmConceptReadFunc)pmConceptRead_FPA_RA,
     335                              (pmConceptWriteFunc)pmConceptWrite_FPA_RA, PM_CONCEPT_LEVEL_FPA);
     336            psFree(fpaRa);
     337        }
    307338
    308339        // FPA.DEC
    309         pmConceptRegister(psMetadataItemAllocF64("FPA.DEC", "Declination of boresight", NAN),
    310                           (pmConceptReadFunc)pmConceptRead_FPA_DEC,
    311                           (pmConceptWriteFunc)pmConceptWrite_FPA_DEC, PM_CONCEPT_LEVEL_FPA);
    312 
     340        {
     341            psMetadataItem *fpaDec = psMetadataItemAllocF64("FPA.DEC", "Declination of boresight", NAN);
     342            pmConceptRegister(fpaDec, (pmConceptReadFunc)pmConceptRead_FPA_DEC,
     343                              (pmConceptWriteFunc)pmConceptWrite_FPA_DEC, PM_CONCEPT_LEVEL_FPA);
     344            psFree(fpaDec);
     345        }
     346
     347        // Done with FPA level concepts
    313348    }
    314349    if (! conceptsChip) {
     
    324359
    325360        // CELL.GAIN
    326         pmConceptRegister(psMetadataItemAllocF32("CELL.GAIN", "CCD gain (e/count)", NAN), NULL, NULL,
    327                           PM_CONCEPT_LEVEL_CELL);
     361        {
     362            psMetadataItem *cellGain = psMetadataItemAllocF32("CELL.GAIN", "CCD gain (e/count)", NAN);
     363            pmConceptRegister(cellGain, NULL, NULL, PM_CONCEPT_LEVEL_CELL);
     364            psFree(cellGain);
     365        }
    328366
    329367        // CELL.READNOISE
    330         pmConceptRegister(psMetadataItemAllocF32("CELL.GAIN", "CCD read noise (e)", NAN), NULL, NULL,
    331                           PM_CONCEPT_LEVEL_CELL);
     368        {
     369            psMetadataItem *cellReadnoise = psMetadataItemAllocF32("CELL.READNOISE",
     370                                            "CCD read noise (e)", NAN);
     371            pmConceptRegister(cellReadnoise, NULL, NULL, PM_CONCEPT_LEVEL_CELL);
     372            psFree(cellReadnoise);
     373        }
    332374
    333375        // CELL.SATURATION
    334         pmConceptRegister(psMetadataItemAllocF32("CELL.SATURATION", "Saturation level (counts)", NAN), NULL,
    335                           NULL, PM_CONCEPT_LEVEL_CELL);
     376        {
     377            psMetadataItem *cellSaturation = psMetadataItemAllocF32("CELL.SATURATION",
     378                                             "Saturation level (counts)", NAN);
     379            pmConceptRegister(cellSaturation, NULL, NULL, PM_CONCEPT_LEVEL_CELL);
     380            psFree(cellSaturation);
     381        }
    336382
    337383        // CELL.BAD
    338         pmConceptRegister(psMetadataItemAllocF32("CELL.BAD", "Bad level (counts)", NAN), NULL, NULL,
    339                           PM_CONCEPT_LEVEL_CELL);
     384        {
     385            psMetadataItem *cellBad = psMetadataItemAllocF32("CELL.BAD", "Bad level (counts)", NAN);
     386            pmConceptRegister(cellBad, NULL, NULL, PM_CONCEPT_LEVEL_CELL);
     387            psFree(cellBad);
     388        }
    340389
    341390        // CELL.XPARITY
    342         pmConceptRegister(psMetadataItemAllocS32("CELL.XPARITY",
    343                           "Orientation in x compared to the rest of the FPA", 0),
    344                           NULL, NULL, PM_CONCEPT_LEVEL_CELL);
     391        {
     392            psMetadataItem *cellXparity = psMetadataItemAllocS32("CELL.XPARITY",
     393                                          "Orientation in x compared to the rest of the FPA", 0);
     394            pmConceptRegister(cellXparity, NULL, NULL, PM_CONCEPT_LEVEL_CELL);
     395            psFree(cellXparity);
     396        }
    345397
    346398        // CELL.YPARITY
    347         pmConceptRegister(psMetadataItemAllocS32("CELL.YPARITY",
    348                           "Orientation in x compared to the rest of the FPA", 0),
    349                           NULL, NULL, PM_CONCEPT_LEVEL_CELL);
     399        {
     400            psMetadataItem *cellYparity = psMetadataItemAllocS32("CELL.YPARITY",
     401                                          "Orientation in x compared to the rest of the FPA", 0);
     402            pmConceptRegister(cellYparity, NULL, NULL, PM_CONCEPT_LEVEL_CELL);
     403            psFree(cellYparity);
     404        }
    350405
    351406        // CELL.READDIR
    352         pmConceptRegister(psMetadataItemAllocS32("CELL.READDIR", "Read direction, rows=1, cols=2", 1), NULL,
    353                           NULL, PM_CONCEPT_LEVEL_CELL);
     407        {
     408            psMetadataItem *cellReaddir = psMetadataItemAllocS32("CELL.READDIR",
     409                                          "Read direction, rows=1, cols=2", 1);
     410            pmConceptRegister(cellReaddir, NULL, NULL, PM_CONCEPT_LEVEL_CELL);
     411            psFree(cellReaddir);
     412        }
    354413
    355414
     
    361420
    362421        // CELL.EXPOSURE
    363         pmConceptRegister(psMetadataItemAllocF32("CELL.EXPOSURE", "Exposure time (sec)", NAN), NULL, NULL,
    364                           PM_CONCEPT_LEVEL_CELL);
     422        {
     423            psMetadataItem *cellExposure = psMetadataItemAllocF32("CELL.EXPOSURE",
     424                                           "Exposure time (sec)", NAN);
     425            pmConceptRegister(cellExposure, NULL, NULL, PM_CONCEPT_LEVEL_CELL);
     426            psFree(cellExposure);
     427        }
    365428
    366429        // CELL.DARKTIME
    367         pmConceptRegister(psMetadataItemAllocF32("CELL.DARKTIME", "Time since flush (sec)", NAN), NULL, NULL,
    368                           PM_CONCEPT_LEVEL_CELL);
     430        {
     431            psMetadataItem *cellDarktime = psMetadataItemAllocF32("CELL.DARKTIME",
     432                                           "Time since flush (sec)", NAN);
     433            pmConceptRegister(cellDarktime, NULL, NULL, PM_CONCEPT_LEVEL_CELL);
     434            psFree(cellDarktime);
     435        }
    369436
    370437        // CELL.TRIMSEC
     
    372439            psRegion *trimsec = psAlloc(sizeof(psRegion)); // Blank trimsec
    373440            trimsec->x0 = trimsec->y0 = trimsec->x1 = trimsec->y1 = NAN;
    374             pmConceptRegister(psMetadataItemAllocPtr("CELL.TRIMSEC", PS_DATA_UNKNOWN, "Trim section",
    375                               trimsec),
    376                               (pmConceptReadFunc)pmConceptRead_CELL_TRIMSEC,
     441            psMetadataItem *cellTrimsec = psMetadataItemAllocPtr("CELL.TRIMSEC", PS_DATA_UNKNOWN,
     442                                          "Trim section", trimsec);
     443            psFree(trimsec);
     444            pmConceptRegister(cellTrimsec, (pmConceptReadFunc)pmConceptRead_CELL_TRIMSEC,
    377445                              (pmConceptWriteFunc)pmConceptWrite_CELL_TRIMSEC, PM_CONCEPT_LEVEL_CELL);
    378             psFree(trimsec);
     446            psFree(cellTrimsec);
    379447        }
    380448
     
    382450        {
    383451            psList *biassecs = psListAlloc(NULL); // Blank biassecs
    384             pmConceptRegister(psMetadataItemAllocPtr("CELL.BIASSEC", PS_DATA_LIST, "Bias sections", biassecs),
    385                               (pmConceptReadFunc)pmConceptRead_CELL_BIASSEC,
    386                               (pmConceptWriteFunc)pmConceptWrite_CELL_TRIMSEC, PM_CONCEPT_LEVEL_CELL);
     452            psMetadataItem *cellBiassec = psMetadataItemAllocPtr("CELL.BIASSEC", PS_DATA_LIST,
     453                                          "Bias sections", biassecs);
    387454            psFree(biassecs);
     455            pmConceptRegister(cellBiassec, (pmConceptReadFunc)pmConceptRead_CELL_BIASSEC,
     456                              (pmConceptWriteFunc)pmConceptWrite_CELL_BIASSEC, PM_CONCEPT_LEVEL_CELL);
     457            psFree(cellBiassec);
    388458        }
    389459
    390460        // CELL.XBIN
    391         pmConceptRegister(psMetadataItemAllocS32("CELL.XBIN", "Binning in x", 0),
    392                           (pmConceptReadFunc)pmConceptRead_CELL_XBIN,
    393                           (pmConceptWriteFunc)pmConceptWrite_CELL_XBIN, PM_CONCEPT_LEVEL_CELL);
     461        {
     462            psMetadataItem *cellXbin = psMetadataItemAllocS32("CELL.XBIN", "Binning in x", 0);
     463            pmConceptRegister(cellXbin, (pmConceptReadFunc)pmConceptRead_CELL_XBIN,
     464                              (pmConceptWriteFunc)pmConceptWrite_CELL_XBIN, PM_CONCEPT_LEVEL_CELL);
     465            psFree(cellXbin);
     466        }
    394467
    395468        // CELL.YBIN
    396         pmConceptRegister(psMetadataItemAllocS32("CELL.YBIN", "Binning in y", 0),
    397                           (pmConceptReadFunc)pmConceptRead_CELL_YBIN,
    398                           (pmConceptWriteFunc)pmConceptWrite_CELL_YBIN, PM_CONCEPT_LEVEL_CELL);
     469        {
     470            psMetadataItem *cellYbin = psMetadataItemAllocS32("CELL.YBIN", "Binning in y", 0);
     471            pmConceptRegister(cellYbin, (pmConceptReadFunc)pmConceptRead_CELL_YBIN,
     472                              (pmConceptWriteFunc)pmConceptWrite_CELL_YBIN, PM_CONCEPT_LEVEL_CELL);
     473            psFree(cellYbin);
     474        }
    399475
    400476        // CELL.TIMESYS
    401         pmConceptRegister(psMetadataItemAllocS32("CELL.TIMESYS", "Time system", -1),
    402                           (pmConceptReadFunc)pmConceptRead_CELL_TIMESYS,
    403                           (pmConceptWriteFunc)pmConceptWrite_CELL_TIMESYS, PM_CONCEPT_LEVEL_CELL);
     477        {
     478            psMetadataItem *cellTimesys = psMetadataItemAllocS32("CELL.TIMESYS", "Time system", -1);
     479            pmConceptRegister(cellTimesys, (pmConceptReadFunc)pmConceptRead_CELL_TIMESYS,
     480                              (pmConceptWriteFunc)pmConceptWrite_CELL_TIMESYS, PM_CONCEPT_LEVEL_CELL);
     481            psFree(cellTimesys);
     482        }
    404483
    405484        // CELL.TIME
     
    409488            time->sec = 0;
    410489            time->nsec = 0;
    411             pmConceptRegister(psMetadataItemAlloc("CELL.TIME", PS_DATA_TIME, "Time of exposure", time),
    412                               (pmConceptReadFunc)pmConceptRead_CELL_TIME,
     490            psMetadataItem *cellTime = psMetadataItemAlloc("CELL.TIME", PS_DATA_TIME,
     491                                       "Time of exposure", time);
     492            psFree(time);
     493            pmConceptRegister(cellTime, (pmConceptReadFunc)pmConceptRead_CELL_TIME,
    413494                              (pmConceptWriteFunc)pmConceptWrite_CELL_TIME, PM_CONCEPT_LEVEL_CELL);
    414             psFree(time);
     495            psFree(cellTime);
    415496        }
    416497
    417498        // CELL.X0
    418         pmConceptRegister(psMetadataItemAllocS32("CELL.X0", "Position of (0,0) on the chip", 0),
    419                           (pmConceptReadFunc)pmConceptRead_CELL_X0,
    420                           (pmConceptWriteFunc)pmConceptWrite_CELL_X0, PM_CONCEPT_LEVEL_CELL);
     499        {
     500            psMetadataItem *cellX0 = psMetadataItemAllocS32("CELL.X0", "Position of (0,0) on the chip", 0);
     501            pmConceptRegister(cellX0, (pmConceptReadFunc)pmConceptRead_CELL_X0,
     502                              (pmConceptWriteFunc)pmConceptWrite_CELL_X0, PM_CONCEPT_LEVEL_CELL);
     503            psFree(cellX0);
     504        }
    421505
    422506        // CELL.Y0
    423         pmConceptRegister(psMetadataItemAllocS32("CELL.Y0", "Position of (0,0) on the chip", 0),
    424                           (pmConceptReadFunc)pmConceptRead_CELL_Y0,
    425                           (pmConceptWriteFunc)pmConceptWrite_CELL_Y0, PM_CONCEPT_LEVEL_CELL);
    426 
    427     }
     507        {
     508            psMetadataItem *cellY0 = psMetadataItemAllocS32("CELL.Y0", "Position of (0,0) on the chip", 0);
     509            pmConceptRegister(cellY0, (pmConceptReadFunc)pmConceptRead_CELL_Y0,
     510                              (pmConceptWriteFunc)pmConceptWrite_CELL_Y0, PM_CONCEPT_LEVEL_CELL);
     511            psFree(cellY0);
     512        }
     513
     514    }
     515
     516    conceptsInitialised = true;
    428517
    429518    return init;
  • branches/eam_rel9_p0/psModules/src/astrom/pmFPA.c

    r6267 r6342  
    1212* XXX: Should we implement non-linear cell->chip transforms?
    1313*
    14 *  @version $Revision: 1.1.2.6 $ $Name: not supported by cvs2svn $
    15 *  @date $Date: 2006-01-31 20:09:52 $
     14*  @version $Revision: 1.1.2.7 $ $Name: not supported by cvs2svn $
     15*  @date $Date: 2006-02-07 21:18:31 $
    1616*
    1717*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3333 *****************************************************************************/
    3434#define PS_FREE_HIERARCHY 1
     35#define PARENT_LINKS 0
     36
    3537static void readoutFree(pmReadout *readout)
    3638{
    3739    if (readout != NULL) {
    38         #if 0
    3940        psTrace(__func__, 9, "Removing readout %lx from cell %lx...\n", (size_t) readout, (size_t) readout->parent);
    4041        if (readout->parent) {
     
    4243            for (int i = 0; i < readouts->n; i++) {
    4344                if (readouts->data[i] == readout) {
    44                     pmReadout *tmpReadout = readouts->data[i];
     45                    //                    pmReadout *tmpReadout = readouts->data[i];
    4546                    readouts->data[i] = NULL;
     47                    #if PARENT_LINKS
     48
    4649                    psFree(tmpReadout);
     50                    #endif
     51
    4752                    break;
    4853                }
    4954            }
    5055        }
     56        psTrace(__func__, 9, "Freeing readout %lx\n", (size_t) readout);
     57
     58        #if PARENT_LINKS
     59
     60        psFree(readout->parent);
    5161        #endif
    52         psTrace(__func__, 9, "Freeing readout %lx\n", (size_t) readout);
    53 
    54         psFree(readout->parent);
    5562
    5663        psFree(readout->image);
     
    6471{
    6572    if (cell != NULL) {
    66         #if 0
    6773        psTrace(__func__, 9, "Removing cell %lx from chip %lx...\n", (size_t)cell, (size_t)cell->parent);
    6874        if (cell->parent) {
     
    7076            for (int i = 0; i < cells->n; i++) {
    7177                if (cells->data[i] == cell) {
    72                     pmCell *tmpCell = cells->data[i];
     78                    //                    pmCell *tmpCell = cells->data[i];
    7379                    cells->data[i] = NULL;
     80                    #if PARENT_LINKS
     81
    7482                    psFree(tmpCell);
     83                    #endif
     84
    7585                    break;
    7686                }
    7787            }
    7888        }
     89        psTrace(__func__, 9, "Freeing cell %lx\n", (size_t)cell);
     90
     91        pmCellFreeReadouts(cell);
     92        psFree(cell->readouts);
     93        #if PARENT_LINKS
     94
     95        psFree(cell->parent);
    7996        #endif
    80         psTrace(__func__, 9, "Freeing cell %lx\n", (size_t)cell);
    81 
    82         pmCellFreeReadouts(cell);
    83         psFree(cell->parent);
    8497
    8598        psFree(cell->toChip);
     
    96109{
    97110    if (chip != NULL) {
    98         #if 0
    99111        psTrace(__func__, 9, "Removing chip %lx from fpa %lx...\n", (size_t)chip, (size_t)chip->parent);
    100112        if (chip->parent) {
     
    102114            for (int i = 0; i < chips->n; i++) {
    103115                if (chips->data[i] == chip) {
    104                     pmChip *tmpChip = chips->data[i];
     116                    //                    pmChip *tmpChip = chips->data[i];
    105117                    chips->data[i] = NULL;
     118                    #if PARENT_LINKS
     119
    106120                    psFree(tmpChip);
     121                    #endif
     122
    107123                    break;
    108124                }
    109125            }
    110126        }
     127        psTrace(__func__, 9, "Freeing chip %lx\n", (size_t)chip);
     128
     129        pmChipFreeCells(chip);
     130        psFree(chip->cells);
     131        #if PARENT_LINKS
     132
     133        psFree(chip->parent);
    111134        #endif
    112         psTrace(__func__, 9, "Freeing chip %lx\n", (size_t)chip);
    113 
    114         pmChipFreeCells(chip);
    115         psFree(chip->parent);
    116135
    117136        psFree(chip->toFPA);
     
    134153        psFree(fpa->analysis);
    135154        psFree(fpa->camera);
    136         #if 1
    137155        //
    138156        // Set the parent to NULL in all fpa->chips before psFree(fpa->chips)
     
    148166            }
    149167        }
    150         #endif
     168        psFree(fpa->chips);
    151169        psFree(fpa->hdu);
    152170        psFree(fpa->phu);
     
    167185        psTrace(__func__, 9, "Will now free readout %lx...\n", (size_t)tmpReadout);
    168186        psFree(tmpReadout); // Drop the readout
     187        #if PARENT_LINKS
     188
    169189        psFree(cell); // Decrement reference counter on cell, since readout->parent isn't held any more
     190        #endif
     191
    170192    }
    171193    cell->readouts = psArrayRealloc(cell->readouts, 0);
     194    cell->readouts->n = 0;
    172195}
    173196
     
    186209        pmCellFreeReadouts(tmpCell);// Drop all readouts the cell holds
    187210        psFree(tmpCell);            // Drop the cell
     211        #if PARENT_LINKS
     212
    188213        psFree(chip); // Decrement reference counter on chip, since cell->parent isn't held any more
     214        #endif
     215
    189216    }
    190217    chip->cells = psArrayRealloc(chip->cells, 0);
     218    chip->cells->n = 0;
    191219}
    192220
     
    219247    tmpReadout->bias = psListAlloc(NULL);
    220248    tmpReadout->analysis = psMetadataAlloc();
     249    #if PARENT_LINKS
     250
    221251    tmpReadout->parent = psMemIncrRefCounter(cell);
     252    #else
     253
     254    tmpReadout->parent = cell;
     255    #endif
     256
    222257    if (cell != NULL) {
    223258        cell->readouts = psArrayAdd(cell->readouts, 1, (psPtr) tmpReadout);
     
    249284    tmpCell->analysis = psMetadataAlloc();
    250285    tmpCell->readouts = psArrayAlloc(0);
     286    #if PARENT_LINKS
     287
    251288    tmpCell->parent = psMemIncrRefCounter(chip);
     289    #else
     290
     291    tmpCell->parent = chip;
     292    #endif
     293
    252294    if (chip != NULL) {
    253295        chip->cells = psArrayAdd(chip->cells, 1, (psPtr) tmpCell);
     
    282324    tmpChip->analysis = psMetadataAlloc();
    283325    tmpChip->cells = psArrayAlloc(0);
     326    #if PARENT_LINKS
     327
    284328    tmpChip->parent = psMemIncrRefCounter(fpa);
     329    #else
     330
     331    tmpChip->parent = fpa;
     332    #endif
     333
    285334    if (fpa != NULL) {
    286335        fpa->chips = psArrayAdd(fpa->chips, 1, (psPtr) tmpChip);
  • branches/eam_rel9_p0/psModules/src/astrom/pmFPAConstruct.c

    r6062 r6342  
    101101                    psMetadata *cellData = getCellData(camera, cellName);
    102102                    pmCell *cell = pmCellAlloc(chip, cellData, cellName); // The cell
    103                     psFree(cell);
    104                     //                  psFree(cellData);
     103                    psFree(cell);       // Drop reference
     104                    //                    psFree(cellData);   // Drop reference
    105105                }
    106106                psFree(cellNamesIter);
    107107                psFree(cellNames);
     108                psFree(chip);           // Drop reference
    108109            }
    109110
     
    141142                    psMetadata *cellData = getCellData(camera, cellType);
    142143                    pmCell *cell = pmCellAlloc(chip, cellData, extName); // The cell
    143                     //                  psFree(cellData);
     144                    //                  psFree(cellData); // Drop reference
    144145                    cell->hdu = p_pmHDUAlloc(extName); // Prepare cell to receive FITS data
    145146
    146                     psFree(chip);
    147                     psFree(cell);
     147                    psFree(cell);       // Drop reference
     148                    psFree(chip);       // Drop reference
    148149                }
    149150                psFree(contents);
     
    172173                    psMetadata *cellData = getCellData(camera, cellName);
    173174                    pmCell *cell = pmCellAlloc(chip, cellData, cellName); // The cell
    174                     psFree(cell);
    175                     //                  psFree(cellData);
     175                    psFree(cell);       // Drop reference
     176                    //                  psFree(cellData);   // Drop reference
    176177                }
    177178                psFree(cellNamesIter);
     179                psFree(chip);           // Drop reference
    178180            }
    179181
     
    255257        }
    256258        psFree(chipName);
    257         psFree(chip);
     259        psFree(chip);                   // Drop reference
    258260
    259261    } else {
Note: See TracChangeset for help on using the changeset viewer.