IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 14904


Ignore:
Timestamp:
Sep 20, 2007, 9:14:51 AM (19 years ago)
Author:
magnier
Message:

fix memory management of parents and children -- inc ref counter on pointer from child to parent

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20070830/psLib/src/imageops/psImageStructManip.c

    r14523 r14904  
    88 *  @author Robert DeSonia, MHPCC
    99 *
    10  *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2007-08-16 02:51:09 $
     10 *  @version $Revision: 1.17.2.1 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2007-09-20 19:14:51 $
    1212 *
    1313 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2323
    2424#include "psMemory.h"
     25#include "psError.h"
     26#include "psAbort.h"
     27
    2528#include "psImageStructManip.h"
    26 #include "psError.h"
    27 
    2829
    2930// col0,row0 are the starting pixel in the input image coordinate frame
     
    9899    if (out != NULL) {
    99100        // if a child, need to orphan (disassociate from parent) first
    100         if (out->parent != NULL) {
    101             psArrayRemoveData(out->parent->children,psMemIncrRefCounter(out));
    102             // remove from parent's knowledge without triggering a free
    103             out->parent = NULL; // break link to parent
     101        psImage *parent = (psImage *) out->parent;
     102        if (parent != NULL) {
     103            // break the back-pointer first so we don't loop
     104            out->parent = NULL;
     105
     106            // drop my entry on my parent's array of children
     107            psArrayRemoveDataNoFree (out->parent->children, out);
     108
     109            // drop my reference to my old parent
     110            psFree (parent);
    104111        }
    105112
     113        // we recycle out->data.V
    106114        psFree(out->p_rawDataBuffer); // free the previous data reference
    107115    } else {
     
    117125    P_PSIMAGE_SET_ROW0(out, row0);
    118126
    119     out->parent = image;
     127    out->parent = psMemIncrRefCounter(image); // track references to parents
    120128    out->children = NULL;
    121129    out->p_rawDataBuffer = rawData;
     
    133141
    134142    // add output image as a child of the input image.
    135     image->children = psArrayAdd(image->children,16,out);
    136     psMemDecrRefCounter(out); // don't count the reference held by parent as a true reference
     143    image->children = psArrayAdd (image->children, 16, out);
     144    psFree (out); // the image->children array is an array of views only
    137145
    138146    return (out);
     
    307315                _("Can not operate on a NULL psImage."));
    308316        return NULL;
     317    }
     318
     319    if ((image->children != NULL) && (image->children->n > 0)) {
     320        psAbort ("cannot trim an image with outstanding children");
    309321    }
    310322
     
    345357    }
    346358
    347     psImageFreeChildren(image);
    348 
    349359    psU32 elementSize = PSELEMTYPE_SIZEOF(image->type.type);
    350360    psU32 numCols = col1-col0;
Note: See TracChangeset for help on using the changeset viewer.