IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6145


Ignore:
Timestamp:
Jan 21, 2006, 5:23:32 PM (20 years ago)
Author:
Paul Price
Message:

Trying to fix memory leaks, but they are a long way down; too hard to find for now.

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

Legend:

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

    r6124 r6145  
    55#include "pmFPA.h"
    66#include "pmChipMosaic.h"
     7
     8#define MEM_LEAKS 1
    79
    810// Compare a value with a maximum and minimum
     
    309311
    310312    // Chop off all the component cells, and put in a new one
     313    #ifndef MEM_LEAKS
     314    pmChipFreeCells(chip);
     315    #else
     316
    311317    chip->cells = psArrayAlloc(0);
     318    #endif
     319
    312320    pmCell *cell = pmCellAlloc(chip, NULL, __func__); // New cell
    313321    cellConcepts(cell, cells, xBinChip, yBinChip);
    314     psFree(cells);
    315322
    316323    #if 1
     
    330337    // Want the readouts to contain a subimage, but that subimage is the whole image.
    331338    // This preserves the relationship there was before, where freeing the parent frees the child.
    332     readout->image = psImageSubset(image, entire);
    333     readout->weight = psImageSubset(weight, entire);
    334     readout->mask = psImageSubset(mask, entire);
     339    readout->image = psMemIncrRefCounter(psImageSubset(image, entire));
     340    readout->weight = psMemIncrRefCounter(psImageSubset(weight, entire));
     341    readout->mask = psMemIncrRefCounter(psImageSubset(mask, entire));
    335342    psFree(readout);
    336343
  • branches/eam_rel9_p0/psModules/src/astrom/pmFPA.c

    r6116 r6145  
    1212* XXX: Should we implement non-linear cell->chip transforms?
    1313*
    14 *  @version $Revision: 1.1.2.4 $ $Name: not supported by cvs2svn $
    15 *  @date $Date: 2006-01-21 06:47:19 $
     14*  @version $Revision: 1.1.2.5 $ $Name: not supported by cvs2svn $
     15*  @date $Date: 2006-01-22 03:23:32 $
    1616*
    1717*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3636{
    3737    if (readout != NULL) {
     38        #if 0
    3839        psTrace(__func__, 9, "Removing readout %lx from cell %lx...\n", (size_t) readout, (size_t) readout->parent);
    3940        if (readout->parent) {
     
    4142            for (int i = 0; i < readouts->n; i++) {
    4243                if (readouts->data[i] == readout) {
     44                    pmReadout *tmpReadout = readouts->data[i];
    4345                    readouts->data[i] = NULL;
     46                    psFree(tmpReadout);
    4447                    break;
    4548                }
    4649            }
    4750        }
     51        #endif
    4852        psTrace(__func__, 9, "Freeing readout %lx\n", (size_t) readout);
     53
     54        psFree(readout->parent);
     55
    4956        psFree(readout->image);
    5057        psFree(readout->mask);
    5158        psFree(readout->weight);
    5259        psFree(readout->analysis);
    53         #if 1
    54 
    55         psMemDecrRefCounter(readout->parent);
    56         #endif
    57 
    5860    }
    5961}
     
    6264{
    6365    if (cell != NULL) {
     66        #if 0
    6467        psTrace(__func__, 9, "Removing cell %lx from chip %lx...\n", (size_t)cell, (size_t)cell->parent);
    6568        if (cell->parent) {
     
    6770            for (int i = 0; i < cells->n; i++) {
    6871                if (cells->data[i] == cell) {
     72                    pmCell *tmpCell = cells->data[i];
    6973                    cells->data[i] = NULL;
     74                    psFree(tmpCell);
    7075                    break;
    7176                }
    7277            }
    7378        }
     79        #endif
    7480        psTrace(__func__, 9, "Freeing cell %lx\n", (size_t)cell);
     81
     82        pmCellFreeReadouts(cell);
     83        psFree(cell->parent);
     84
    7585        psFree(cell->toChip);
    7686        psFree(cell->toFPA);
     
    7989        psFree(cell->analysis);
    8090        psFree(cell->camera);
    81         #if 1
    82         //
    83         // Set the parent to NULL in all cell->readouts before psFree(cell->readouts)
    84         // in order to avoid memory reference counter problems.
    85         //
    86         psArray *readouts = cell->readouts;
    87         for (psS32 i = 0 ; i < readouts->n ; i++) {
    88             pmReadout *tmpReadout = readouts->data[i];
    89             readouts->data[i] = NULL;
    90             tmpReadout->parent = NULL;
    91             if (PS_FREE_HIERARCHY == 1) {
    92                 psTrace(__func__, 9, "Will now free readout %lx...\n", (size_t)tmpReadout);
    93                 psFree(tmpReadout);
    94             }
    95         }
    96         psMemDecrRefCounter(cell->parent);
    97         #endif
    98 
    9991        psFree(cell->hdu);
    10092    }
     
    10496{
    10597    if (chip != NULL) {
     98        #if 0
    10699        psTrace(__func__, 9, "Removing chip %lx from fpa %lx...\n", (size_t)chip, (size_t)chip->parent);
    107100        if (chip->parent) {
     
    109102            for (int i = 0; i < chips->n; i++) {
    110103                if (chips->data[i] == chip) {
     104                    pmChip *tmpChip = chips->data[i];
    111105                    chips->data[i] = NULL;
     106                    psFree(tmpChip);
    112107                    break;
    113108                }
    114109            }
    115110        }
     111        #endif
    116112        psTrace(__func__, 9, "Freeing chip %lx\n", (size_t)chip);
     113
     114        pmChipFreeCells(chip);
     115        psFree(chip->parent);
    117116
    118117        psFree(chip->toFPA);
     
    120119        psFree(chip->concepts);
    121120        psFree(chip->analysis);
    122         #if 1
    123         //
    124         // Set the parent to NULL in all chip->cells before psFree(chip->cells)
    125         // in order to avoid memory reference counter problems.
    126         //
    127         psArray *cells = chip->cells;
    128         for (psS32 i = 0 ; i < cells->n ; i++) {
    129             pmCell *tmpCell = cells->data[i];
    130             cells->data[i] = NULL;
    131             tmpCell->parent = NULL;
    132             if (PS_FREE_HIERARCHY == 1) {
    133                 psFree(tmpCell);
    134             }
    135         }
    136         psMemDecrRefCounter(chip->parent);
    137         #endif
    138 
    139121        psFree(chip->hdu);
    140122    }
     
    172154}
    173155
     156void pmCellFreeReadouts(pmCell *cell)
     157{
     158    //
     159    // Set the parent to NULL in all cell->readouts before psFree(cell->readouts)
     160    // in order to avoid memory reference counter problems.
     161    //
     162    psArray *readouts = cell->readouts;
     163    for (psS32 i = 0 ; i < readouts->n ; i++) {
     164        pmReadout *tmpReadout = readouts->data[i];
     165        readouts->data[i] = NULL;
     166        tmpReadout->parent = NULL;
     167        psTrace(__func__, 9, "Will now free readout %lx...\n", (size_t)tmpReadout);
     168        psFree(tmpReadout); // Drop the readout
     169        psFree(cell); // Decrement reference counter on cell, since readout->parent isn't held any more
     170    }
     171    cell->readouts = psArrayRealloc(cell->readouts, 0);
     172}
     173
     174
     175void pmChipFreeCells(pmChip *chip)
     176{
     177    //
     178    // Set the parent to NULL in all chip->cells before psFree(chip->cells)
     179    // in order to avoid memory reference counter problems.
     180    //
     181    psArray *cells = chip->cells;
     182    for (int i = 0 ; i < cells->n ; i++) {
     183        pmCell *tmpCell = cells->data[i];
     184        cells->data[i] = NULL;
     185        tmpCell->parent = NULL;
     186        pmCellFreeReadouts(tmpCell);// Drop all readouts the cell holds
     187        psFree(tmpCell);            // Drop the cell
     188        psFree(chip); // Decrement reference counter on chip, since cell->parent isn't held any more
     189    }
     190    chip->cells = psArrayRealloc(chip->cells, 0);
     191}
     192
     193
     194
    174195void p_pmHDUFree(p_pmHDU *hdu)
    175196{
     
    572593
    573594        if (! readout->weight) {
    574             readout->weight = psImageSubset(weights->data[i], *trimsec);
     595            readout->weight = psMemIncrRefCounter(psImageSubset(weights->data[i], *trimsec));
    575596        }
    576597        if (! readout->mask) {
    577             readout->mask = psImageSubset(masks->data[i], *trimsec);
     598            readout->mask = psMemIncrRefCounter(psImageSubset(masks->data[i], *trimsec));
    578599        }
    579600
  • branches/eam_rel9_p0/psModules/src/astrom/pmFPA.h

    r6080 r6145  
    77*  @author GLG, MHPCC
    88*
    9 *  @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
    10 *  @date $Date: 2006-01-20 09:47:06 $
     9*  @version $Revision: 1.1.2.3 $ $Name: not supported by cvs2svn $
     10*  @date $Date: 2006-01-22 03:23:32 $
    1111*
    1212*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    159159pmReadout;
    160160
     161void pmCellFreeReadouts(pmCell *cell);
     162void pmChipFreeCells(pmChip *chip);
    161163
    162164/** Allocates a pmReadout
  • branches/eam_rel9_p0/psModules/src/astrom/pmFPARead.c

    r6124 r6145  
    115115        pmReadout *readout = pmReadoutAlloc(cell);
    116116
    117         readout->image = psImageSubset(image, *trimsec); // The image corresponding to the trim region
     117        readout->image = psMemIncrRefCounter(psImageSubset(image, *trimsec)); // The image corresponding to the trim region
    118118
    119119        // Get the list of overscans
Note: See TracChangeset for help on using the changeset viewer.