IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 10470


Ignore:
Timestamp:
Dec 4, 2006, 6:08:20 PM (20 years ago)
Author:
Paul Price
Message:

Fixing memory corruption aborts caused by double frees.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/config/pmConfigRecipes.c

    r10436 r10470  
    286286        }
    287287
    288         psMetadata *recipe = NULL;
    289         psMetadata *current = NULL;
    290 
    291         # if (0)
    292 
    293             psString comment = NULL;
     288        #if (0)
     289        psString comment = NULL;
    294290        psStringAppend(&comment, "Recipe added at %s from %s", sourceName, (char*)fileItem->data.V);
    295291        psTrace ("psModules.pmConfig", 3, comment);
    296292        psMetadataAddS32(config->recipesSource, PS_LIST_TAIL, fileItem->name, PS_META_REPLACE, comment, sourceType);
    297293        psFree(comment);
    298         # endif
     294        #endif
    299295
    300296        // Read the recipe file.
     297        psMetadata *recipe = NULL;
    301298        if (!pmConfigFileRead(&recipe, fileItem->data.V, "recipe")) {
    302299            psError(PS_ERR_IO, false, "Failed to read recipe");
     
    307304
    308305        // if this named recipe exists, supplement it
    309         current = psMemIncrRefCounter (psMetadataLookupMetadata (NULL, config->recipes, fileItem->name));
     306        psMetadata *current = psMemIncrRefCounter(psMetadataLookupMetadata(NULL, config->recipes,
     307                              fileItem->name));
    310308        current = psMetadataCopy (current, recipe);
    311         psMetadataAdd(config->recipes, PS_LIST_TAIL, fileItem->name, PS_DATA_METADATA | PS_META_REPLACE, fileItem->comment, current);
    312309        psFree(recipe);  // Drop reference
     310        psMetadataAdd(config->recipes, PS_LIST_TAIL, fileItem->name, PS_DATA_METADATA | PS_META_REPLACE,
     311                      fileItem->comment, current);
    313312        psFree(current);  // Drop reference
    314313    }
     
    340339    psMetadataItem *item = NULL;    // MD item containing the filename, from recipe iteration
    341340    while ((item = psMetadataGetAndIncrement(recipesIter))) {
    342         psMetadata *recipe = NULL;
    343         psMetadata *current = NULL;
    344 
    345341        // type mismatch is a serious error
    346342        if (item->type != PS_DATA_METADATA) {
     
    348344        }
    349345        // increment the ref counter to protect the data
    350         recipe = psMemIncrRefCounter (item->data.V);
     346
     347        psMetadata *recipe = item->data.V; // Recipe of interest
    351348
    352349        // if this named recipe exists, supplement it
    353         current = psMemIncrRefCounter (psMetadataLookupMetadata (NULL, config->recipes, item->name));
     350        psMetadata *current = psMemIncrRefCounter(psMetadataLookupMetadata(NULL, config->recipes,
     351                              item->name));
    354352        current = psMetadataCopy (current, recipe);
    355         psMetadataAdd(config->recipes, PS_LIST_TAIL, item->name, PS_DATA_METADATA | PS_META_REPLACE, "added from command-line recipe", current);
    356         psFree(recipe);  // Drop reference
     353        psMetadataAdd(config->recipes, PS_LIST_TAIL, item->name, PS_DATA_METADATA | PS_META_REPLACE,
     354                      "added from command-line recipe", current);
    357355        psFree(current);  // Drop reference
    358356    }
     
    375373    while ((item = psMetadataGetAndIncrement(recipesIter))) {
    376374        assert(item->type == PS_DATA_STRING); // It should be this type: we put it in ourselves
    377         const char *symbolRef = psStringCopy (item->data.V); // The name of the symbolic reference
    378         const char *symbolName = psStringCopy (item->name);
    379 
    380         psMetadata *current = NULL;
    381         psMetadata *recipe = NULL;
     375        const char *symbolRef = item->data.V; // The name of the symbolic reference
     376        const char *symbolName = item->name;
    382377
    383378        // search for linkName in config->recipes
    384         recipe = psMetadataLookupMetadata(NULL, config->recipes, symbolRef); // The source
     379        psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, symbolRef); // The source
    385380        if (recipe) {
    386381            // if this named recipe exists, supplement it
    387             current = psMemIncrRefCounter (psMetadataLookupMetadata (NULL, config->recipes, symbolName));
    388             current = psMetadataCopy (current, recipe);
    389             psMetadataAdd(config->recipes, PS_LIST_TAIL, symbolName, PS_DATA_METADATA | PS_META_REPLACE, symbolRef, current);
     382            psMetadata *current = psMemIncrRefCounter(psMetadataLookupMetadata(NULL, config->recipes,
     383                                  symbolName));
     384            current = psMetadataCopy(current, recipe);
     385            psMetadataAdd(config->recipes, PS_LIST_TAIL, symbolName, PS_DATA_METADATA | PS_META_REPLACE,
     386                          symbolRef, current);
    390387            psFree(current);  // Drop reference
    391             psFree (symbolName);
    392             psFree (symbolRef);
    393388            continue;
    394389        }
    395390
    396391        // search for linkName in config->recipes:NAME
    397         current = psMetadataLookupMetadata(NULL, config->recipes, symbolName); // The source
     392        psMetadata *current = psMetadataLookupMetadata(NULL, config->recipes, symbolName); // The source
    398393        if (current) {
    399394            recipe = psMetadataLookupMetadata(NULL, current, symbolRef); // The source
    400395            if (recipe) {
    401396                // supplement the existing recipe
    402                 current = psMetadataCopy (current, recipe);
    403                 psMetadataAdd(config->recipes, PS_LIST_TAIL, symbolName, PS_DATA_METADATA | PS_META_REPLACE, symbolRef, current);
     397                psMetadataCopy (current, recipe);
     398                psMetadataAdd(config->recipes, PS_LIST_TAIL, symbolName, PS_DATA_METADATA | PS_META_REPLACE,
     399                              symbolRef, current);
    404400                continue;
    405401            }
    406             psFree(recipe);  // Drop reference
    407             psFree(current);  // Drop reference
    408             psFree (symbolName);
    409             psFree (symbolRef);
    410         }
    411         psFree (symbolName);
    412         psFree (symbolRef);
     402        }
    413403        // symbol is not found: ERROR
    414404    }
Note: See TracChangeset for help on using the changeset viewer.