IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 8338


Ignore:
Timestamp:
Aug 14, 2006, 5:13:05 PM (20 years ago)
Author:
Paul Price
Message:

Plugging memory leaks.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppStats/src/ppStatsLoop.c

    r8337 r8338  
    4747}
    4848
     49static void addToHierarchy(psMetadata *source, // Source to add
     50                           psMetadata *target, // Target to which to add
     51                           const char *name, // Name of source
     52                           const char *comment // Comment for source
     53    )
     54{
     55    if (psListLength(source->list) > 0 && !psMetadataLookup(target, name)) {
     56        psMetadataAdd(target, PS_LIST_TAIL, name, PS_DATA_METADATA,
     57                      comment, source);
     58    }
     59    psFree(source);                     // Drop reference
     60    return;
     61}
     62
    4963
    5064psMetadata *ppStatsLoop(psMetadata *fpaResults, // Metadata to hold the FPA results
     
    96110        }
    97111
    98         psMetadata *chipResults = psMetadataLookupMD(&mdok, fpaResults, chipName); // Chip-level results
     112        // Chip-level results
     113        psMetadata *chipResults = psMemIncrRefCounter(psMetadataLookupMD(&mdok, fpaResults, chipName));
    99114        if (!mdok || !chipResults) {
    100115            chipResults = psMetadataAlloc();
     
    129144            }
    130145
    131             psMetadata *cellResults = psMetadataLookupMD(&mdok, chipResults, cellName); // Cell-level results
     146            // Cell-level results
     147            psMetadata *cellResults = psMemIncrRefCounter(psMetadataLookupMD(&mdok, chipResults, cellName));
    132148            if (!mdok || !cellResults) {
    133149                cellResults = psMetadataAlloc();
     
    136152            if (psListLength(data->headers) > 0 && cell->hdu) {
    137153                if (fits && !pmCellReadHeader(cell, fits)) {
     154                    addToHierarchy(cellResults, chipResults, cellName, "Results for cell");
    138155                    continue;
    139156                }
     
    143160            if (psListLength(data->concepts) > 0) {
    144161                if (fits && !pmCellReadHeader(cell, fits)) {
     162                    addToHierarchy(cellResults, chipResults, cellName, "Results for cell");
    145163                    continue;
    146164                }
     
    155173                                  "Results for cell", cellResults);
    156174                }
     175                addToHierarchy(cellResults, chipResults, cellName, "Results for cell");
    157176                continue;
    158177            }
     
    160179            pmHDU *hdu = pmHDUFromCell(cell); // HDU for cell
    161180            if (!hdu || hdu->blankPHU) {
     181                addToHierarchy(cellResults, chipResults, cellName, "Results for cell");
    162182                continue;
    163183            }
     
    166186                psLogMsg(__func__, PS_LOG_WARN, "Unable to read chip %s cell %s\n", chipName, cellName);
    167187                pmCellFreeData(cell);
     188                addToHierarchy(cellResults, chipResults, cellName, "Results for cell");
    168189                continue;
    169190            }
     
    171192            psArray *readouts = cell->readouts; // Array of component readouts
    172193            if (readouts->n == 0) {
    173                 pmCellFreeData(cell);
     194                if (fits) {
     195                    pmCellFreeData(cell);
     196                }
     197                addToHierarchy(cellResults, chipResults, cellName, "Results for cell");
    174198                continue;
    175199            }
     
    182206                psLogMsg(__func__, PS_LOG_WARN, "No image associated with readout in chip %s cell %s --- "
    183207                         "ignored.\n", chipName, cellName);
    184                 pmCellFreeData(cell);
     208                if (fits) {
     209                    pmCellFreeData(cell);
     210                }
     211                addToHierarchy(cellResults, chipResults, cellName, "Results for cell");
    185212                continue;
    186213            }
     
    191218                    psLogMsg(__func__, PS_LOG_WARN, "Unable to perform statistics on chip %s cell %s --- "
    192219                             "ignored.\n", chipName, cellName);
    193                     pmCellFreeData(cell);
     220                    if (fits) {
     221                        pmCellFreeData(cell);
     222                    }
     223                    addToHierarchy(cellResults, chipResults, cellName, "Results for cell");
    194224                    continue;
    195225                }
     
    221251                    psFree(sampleValues);
    222252                    psFree(sampleMask);
    223                     pmCellFreeData(cell);
     253                    if (fits) {
     254                        pmCellFreeData(cell);
     255                    }
     256                    addToHierarchy(cellResults, chipResults, cellName, "Results for cell");
    224257                    continue;
    225258                }
     
    249282
    250283            // Add the cell results to the chip
    251             if (psListLength(cellResults->list) > 0 && !psMetadataLookup(chipResults, cellName)) {
    252                 psMetadataAdd(chipResults, PS_LIST_TAIL, cellName, PS_DATA_METADATA,
    253                               "Results for cell", cellResults);
    254                 psFree(cellResults);
    255             }
    256 
     284            addToHierarchy(cellResults, chipResults, cellName, "Results for cell");
    257285            if (fits) {
    258286                pmCellFreeData(cell);
    259287            }
    260288        }
     289
     290        addToHierarchy(chipResults, fpaResults, chipName, "Results for chip");
    261291        if (fits) {
    262292            pmChipFreeData(chip);
    263293        }
    264294
    265         if (psListLength(chipResults->list) > 0 && !psMetadataLookup(fpaResults, chipName)) {
    266             psMetadataAdd(fpaResults, PS_LIST_TAIL, chipName, PS_DATA_METADATA,
    267                           "Results for chip", chipResults);
    268             psFree(chipResults);
    269         }
    270295    }
    271296    if (fits) {
    272297        pmFPAFreeData(fpa);
    273298    }
    274 
    275299    psFree(headersIter);
    276300    psFree(conceptsIter);
Note: See TracChangeset for help on using the changeset viewer.