IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 4, 2004, 1:44:15 PM (22 years ago)
Author:
gusciora
Message:

Located the memory leak.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/sysUtils/tst_psHash03.c

    r862 r873  
    99#include "psTest.h"
    1010#include "psHash.h"
     11#include "psMemory.h"
    1112#define NUM_HASH_TABLE_BUCKETS 100
    1213int imGlobal = 0;
     14int currentId = 0;
    1315
    1416typedef struct
     
    1719}
    1820ID;
     21
     22// NOTE: This is my own little routine I used in debugging a memory
     23// leak.  I will take this out of this file later.
     24void printMemBlocks(char *myString)
     25{
     26    psMemBlock **memBlocks = NULL;
     27    psMemBlock *tmp = NULL;
     28    int numBlocks = 0;
     29
     30    numBlocks = psMemCheckLeaks(currentId, &memBlocks, NULL);
     31    printf("******************** %s ********************\n", myString);
     32    printf("%d mem blocks\n", psMemCheckLeaks(currentId,NULL,NULL));
     33    printf("%d blocks\n", numBlocks);
     34    printf("*  ");
     35    if (memBlocks != NULL) {
     36        for (tmp = *memBlocks; tmp != NULL; tmp = tmp->nextBlock) {
     37            printf("%d ", (int) tmp->id);
     38        }
     39    }
     40    printf("*\n");
     41    printf("*************************************************\n");
     42    psFree(memBlocks);
     43}
     44
    1945static ID *IdAlloc(const char *name)
    2046{
    21     ID *id = psAlloc(sizeof(ID));
     47    ID *id = NULL;
     48
     49    id = psAlloc(sizeof(ID));
     50
    2251    id->name = psStringCopy(name);
    2352
     
    4069    char *myKeys[] = {"ENTRY00", "ENTRY01", "ENTRY02", "ENTRY03", NULL};
    4170    char *myData[] = {"IDA", "IDB", "IDC", "IDD", NULL};
    42     int currentId = psMemGetId();
    4371    int memLeaks        = 0;
     72
     73    currentId = psMemGetId();
    4474
    4575    printPositiveTestHeader(stdout,
     
    4878
    4979    myHashTable = psHashAlloc(NUM_HASH_TABLE_BUCKETS);
     80
    5081    i = 0;
    5182    while (myKeys[i] != NULL) {
     
    5485        i++;
    5586    }
    56 
    5787
    5888    i = 0;
     
    6696    }
    6797
    68 
    6998    i = 0;
    7099    while (myKeys[i] != NULL) {
    71         id = psHashRemove(myHashTable, myKeys[i]);
     100        id = psHashRemove(myHashTable, myKeys[i], (void (*)(void *))IdFree);
     101        IdFree(id);
    72102        id = psHashLookup(myHashTable, myKeys[i]);
    73103        if (id != NULL) {
     
    78108    }
    79109
    80 
    81110    printFooter(stdout,
    82111                "psHash functions",
     
    84113                testStatus);
    85114
    86     memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
    87     printf("HMMM: %d memory leaks.  Callin psHashFree()\n", memLeaks);
    88115    psHashFree(myHashTable, (void (*)(void *))IdFree);
    89116    memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
Note: See TracChangeset for help on using the changeset viewer.