IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 1375


Ignore:
Timestamp:
Aug 3, 2004, 3:21:33 PM (22 years ago)
Author:
harman
Message:

Removed recursive psFree and memory errors caused by deleting the same pointer twice

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/sysUtils/psHash.c

    r1371 r1375  
    99*  @author Robert Lupton, Princeton University
    1010*  @author George Gusciora, MHPCC
    11 *   
    12 *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2004-08-02 22:31:02 $
     11*
     12*  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2004-08-04 01:21:33 $
    1414*
    1515*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3838    table: a hash table
    3939Return;
    40     The linked list 
     40    The linked list
    4141 *****************************************************************************/
    4242psList *psHashKeyList( psHash *table )
     
    114114/******************************************************************************
    115115hashBucketFree(bucket): This procedure deallocates the specified
    116 hash bucket. 
     116hash bucket.
    117117Inputs:
    118118    bucket: the hash bucket to be freed.
     
    144144    The new hash table.
    145145 *****************************************************************************/
    146 psHash *psHashAlloc( int nbucket )  // initial number of buckets
     146psHash *psHashAlloc( int nbucket )   // initial number of buckets
    147147{
    148148    int i = 0;   // loop index variable
     
    181181static void hashFree( psHash *table )
    182182{
    183     psHashBucket * tmp = NULL;           // Used to step through linked list.
    184     psHashBucket *ptr = NULL;           // Used to step through linked list.
    185183    int i = 0;                          // Loop index variable.
    186184   
     
    191189    // Loop through each bucket in the hash table.  If that bucket is not
    192190    // NULL, then free the bucket via a function call to hashBucketFree();
    193    
    194191    for ( i = 0; i < table->nbucket; i++ ) {
    195             // A bucket is composed of a linked list of buckets.  We use the
    196             // "tmp" and "ptr" pointers to step through that list and free each
    197             // non-NULL bucket.
    198            
     192   
     193            // A bucket is composed of a linked list of buckets.
    199194            if ( table->buckets[ i ] != NULL ) {
    200                     ptr = table->buckets[ i ];
    201                     while ( ptr != NULL ) {
    202                             tmp = ptr->next;
    203                             psFree( ptr );
    204                             ptr = tmp;
    205                         }
     195                    psFree( table->buckets[ i ] );
    206196                }
    207197        }
     
    359349    itemFree: a function pointer
    360350Return:
    361     boolean value defining success or failure 
     351    boolean value defining success or failure
    362352 *****************************************************************************/
    363353bool psHashAdd( psHash *table, const char *key, void *data )
     
    387377    The data associated with that key.
    388378 *****************************************************************************/
    389 void *psHashLookup( psHash *table,    // table to lookup key in
    390                     const char *key )  // key to lookup
     379void *psHashLookup( psHash *table,     // table to lookup key in
     380                    const char *key )   // key to lookup
    391381{
    392382    if ( table == NULL ) {
Note: See TracChangeset for help on using the changeset viewer.