IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

Squashing memory leaks

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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);
Note: See TracChangeset for help on using the changeset viewer.