IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 12825


Ignore:
Timestamp:
Apr 12, 2007, 2:22:35 PM (19 years ago)
Author:
Paul Price
Message:

Fixed bug: replacing an item with itself can lead to memory corruption
when you blow away what you're trying to add. Also did some cleaning
up.

File:
1 edited

Legend:

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

    r12572 r12825  
    1212 *  @author Ross Harman, MHPCC
    1313 *
    14  *  @version $Revision: 1.158 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2007-03-23 23:25:02 $
     14 *  @version $Revision: 1.159 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2007-04-13 00:22:35 $
    1616 *
    1717 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    597597
    598598    // how the item is added to the hash depends on prior existence, flags, etc.
    599     if(existingEntry != NULL) { // prior existence
    600         if (existingEntry->type == PS_DATA_METADATA_MULTI || (flags & PS_META_DUPLICATE_OK) != 0) {
     599    if (existingEntry) { // prior existence
     600        if (existingEntry->type == PS_DATA_METADATA_MULTI || (flags & PS_META_DUPLICATE_OK)) {
    601601            // duplicate entries allowed - add another entry.
    602602
     
    605605
    606606            // add to the hash's list of duplicate entries
    607             if (! psListAdd(existingEntry->data.list, PS_LIST_TAIL, (psPtr)item) ) {
     607            if (!psListAdd(existingEntry->data.list, PS_LIST_TAIL, (psPtr)item) ) {
    608608                psError(PS_ERR_UNKNOWN, false,
    609609                        _("Failed to add metadata item, %s, to metadata collection list."),
     
    611611                return false;
    612612            }
    613         } else if ((flags & PS_META_REPLACE) != 0) {
     613        } else if (flags & PS_META_REPLACE) {
    614614            // replace entry instead of creating a duplicate entry.
    615615
     
    618618                return false;
    619619            }
    620 
    621             // remove the existing entry from metadata
    622             psMetadataRemoveKey(md, key);
    623 
    624             // treat as if new (added to list below)
    625             /*  The following is unneeded.  HashAdd can't return false with non-null inputs.
    626                         if(!psHashAdd(mdTable, key, (psPtr)item)) {
    627                             psError(PS_ERR_UNKNOWN,false,
    628                                 _("Failed to add metadata item, %s, to items table."),key);
    629                             return false;
    630                         }
    631             */
    632             psHashAdd(mdTable, key, (psPtr)item);
    633 
    634             // Generate warning that item has been replaced
    635             //            psLogMsg(__func__,PS_LOG_WARN,"Metadata item %s has been replaced",
    636             //                     existingEntry->name);
     620            if (item != existingEntry) {
     621                // Replacing an item with itself can lead to memory corruption
     622                // when you blow away what you're trying to add
     623                psMetadataRemoveKey(md, key);
     624                psHashAdd(mdTable, key, (psPtr)item);
     625            }
    637626        } else {
    638627            // default is to error on duplicate entry.
    639             if ((flags & PS_META_NO_REPLACE) != 0) {
     628            if (flags & PS_META_NO_REPLACE) {
    640629                return true;
    641630            }
Note: See TracChangeset for help on using the changeset viewer.