IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18955


Ignore:
Timestamp:
Aug 8, 2008, 8:06:27 AM (18 years ago)
Author:
Paul Price
Message:

Fixing memory problem with psListGetAndRemove. This function must increment the reference counter, since the item may be on the list with no-one else holding the reference.

Location:
trunk/psLib/src/types
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/types/psList.c

    r18825 r18955  
    77 *  @author Joshua Hoblitt, University of Hawaii
    88 *
    9  *  @version $Revision: 1.70 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2008-07-31 23:41:04 $
     9 *  @version $Revision: 1.71 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2008-08-08 18:06:27 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    457457
    458458// simultaneous get and remove (ie, 'pop')
    459 psPtr psListGetAndRemove (psList *list, long location) {
     459psPtr psListGetAndRemove(psList *list, long location) {
    460460
    461461    PS_ASSERT_LIST_NON_NULL(list, NULL);
    462462
    463     // empty list : 
     463    // empty list :
    464464    // XXX handle this explicitly since psListGet raises an error in this case
    465     if (list->head == NULL) return NULL;
    466 
    467     psPtr *item = psListGet (list, location);
    468 
    469     psListRemove (list, location);
     465    if (list->head == NULL) {
     466        return NULL;
     467    }
     468
     469    psPtr *item = psListGet (list, location); // Item of interest
     470    if (psMemIncrRefCounter(item)) {    // To prevent psListRemove from killing the item before it gets out
     471        psListRemove(list, location);
     472    }
     473
    470474    return item;
    471475}
  • trunk/psLib/src/types/psList.h

    r18825 r18955  
    55 *  @author Robert Daniel DeSonia, MHPCC
    66 *
    7  *  @version $Revision: 1.47 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2008-07-31 23:41:04 $
     7 *  @version $Revision: 1.48 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2008-08-08 18:06:27 $
    99 *
    1010 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    215215 *                      NULL is returned.
    216216 */
    217 psPtr psListGetAndRemove (
    218     psList *list,                       ///< list from which to get and remove the element
    219     long location                       ///< index of item
     217psPtr psListGetAndRemove(
     218    psList *list,                       ///< list from which to get and remove the element
     219    long location                       ///< index of item
    220220);
    221221
Note: See TracChangeset for help on using the changeset viewer.