IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 7, 2006, 8:52:03 PM (20 years ago)
Author:
eugene
Message:

extensive cleanup of memory handling : no more leaks!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/psphotSourceFits.c

    r6056 r6379  
    5454
    5555    // extended source model descriptions
    56     char *modelNameEXT = psMetadataLookupPtr (&status, config, "EXT_MODEL");
     56    char *modelNameEXT = psMetadataLookupStr (&status, config, "EXT_MODEL");
    5757    modelTypeEXT = pmModelSetType (modelNameEXT);
    5858    psphotInitRadiusEXT (config, sky, modelTypeEXT);
     
    7777    psTrace ("psphot.blend", 5, "trying blob...\n");
    7878
     79    // this temporary source is used as a place-holder by the psphotEval functions below
    7980    pmSource *tmpSrc = pmSourceAlloc ();
    8081
     
    8990    chiDBL = ONE->chisq / ONE->nDOF;
    9091
     92    psFree (tmpSrc); // XXX should I keep / save the flags set in the eval functions?
     93
    9194    if (okEXT && okDBL) {
    9295        psTrace ("psphot.blend", 5, "blob chisq: %f vs %f\n", chiEXT, chiDBL);
     
    98101    if (okEXT && !okDBL) goto keepEXT;
    99102    if (!okEXT && okDBL) goto keepDBL;
     103
     104    // both models failed; reject them both
     105    psFree (EXT);
     106    psFree (DBL);
    100107    return false;
    101108
    102109keepEXT:
    103110    // sub EXT
     111    psFree (DBL);
    104112    pmSourceSubModel (source->pixels, source->mask, EXT, false, false);
    105113    psTrace ("psphot.blend", 5, "blob as EXT: %f %f\n", EXT->params->data.F32[2], EXT->params->data.F32[3]);
     
    113121keepDBL:
    114122    // sub DLB
     123    psFree (EXT);
    115124    pmSourceSubModel (source->pixels, source->mask, (pmModel *) DBL->data[0], false, false);
    116125    pmSourceSubModel (source->pixels, source->mask, (pmModel *) DBL->data[1], false, false);
     
    120129    source->mode |=  PM_SOURCE_SUBTRACTED;
    121130    source->mode &= ~PM_SOURCE_TEMPSUB;
    122 
    123     // save new model
    124     // tmpSrc->modelPSF = (pmModel *) modelSet->data[1];
    125     // psArrayAdd (sources, 100, tmpSrc);
    126131
    127132    return true;
     
    205210        return status;
    206211    }
    207 
    208212    psTrace ("psphot.blend", 5, "trying blend...\n");
    209213
     
    225229    psArrayAdd (sourceSet, 16, source);
    226230
     231    // counter to track the blend elements used in the fit
     232    psVector *index  = psVectorAlloc (source->blends->n + 1, PS_TYPE_S32);
     233    index->data.S32[0] = -1; // first element corresponds to the primary source
     234
    227235    for (int i = 0; i < source->blends->n; i++) {
    228236        pmSource *blend = source->blends->data[i];
     
    237245        pmModel *model = blend->modelPSF;
    238246
    239         for (psS32 i = 0; i < model->params->n; i++) {
    240             model->params->data.F32[i] = PSF->params->data.F32[i];
    241             model->dparams->data.F32[i] = PSF->dparams->data.F32[i];
     247        for (int j = 0; j < model->params->n; j++) {
     248            model->params->data.F32[j] = PSF->params->data.F32[j];
     249            model->dparams->data.F32[j] = PSF->dparams->data.F32[j];
    242250        }
    243251
     
    247255
    248256        // add this blend to the list
     257        index->data.S32[modelSet->n] = i;
    249258        psArrayAdd (modelSet, 16, model);
    250259        psArrayAdd (sourceSet, 16, blend);
     
    261270        pmModel *model = modelSet->data[i];
    262271
     272        // if we skip this one, free the corresponding blend entry model
    263273        if (!psphotEvalPSF (src, model)) {
    264             psFree (model);
    265             src->modelPSF = NULL;
     274            int n = index->data.S32[i];
     275            pmSource *blend = source->blends->data[n];
     276            psFree (blend->modelPSF);
     277            blend->modelPSF = NULL;
    266278            continue;
    267279        }
     
    272284        src->mode &= ~PM_SOURCE_TEMPSUB;
    273285    }
     286    psFree (index);
     287    psFree (modelSet);
     288    psFree (sourceSet);
    274289
    275290    // evaluate the primary object
     
    281296    psTrace ("psphot.blend", 5, "fitted primary as PSF\n");
    282297    pmSourceSubModel (source->pixels, source->mask, PSF, false, false);
     298    psFree (source->modelPSF);
    283299    source->modelPSF = PSF;
    284300    source->mode |=  PM_SOURCE_SUBTRACTED;
Note: See TracChangeset for help on using the changeset viewer.