IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 4, 2007, 3:56:34 PM (19 years ago)
Author:
jhoblitt
Message:

change badMemBlock() to call psMemBlockPrint() directly
change badMemBlock() to check for all possible errors and not just stop after the first one is encountered
misc error format cleanups

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/jch-memory/psLib/src/sys/psMemory.c

    r10906 r10907  
    99*  @author Joshua Hoblitt, University of Hawaii
    1010*
    11 *  @version $Revision: 1.88.2.14 $ $Name: not supported by cvs2svn $
    12 *  @date $Date: 2007-01-05 01:15:33 $
     11*  @version $Revision: 1.88.2.15 $ $Name: not supported by cvs2svn $
     12*  @date $Date: 2007-01-05 01:56:34 $
    1313*
    1414*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    5858fprintf(stderr, "%s (%s:%d) ", func, filename, lineno); \
    5959fprintf(stderr, __VA_ARGS__);\
    60 psErrorStackPrint(stderr, "\nAborting.  Error stack:"); \
     60psErrorStackPrint(stderr, "\nAborting.  Error stack:\n"); \
    6161fprintf(stderr, "\n");\
    6262abort();
     
    7474#define HANDLE_BAD_BLOCK(memBlock, file, lineo, func) \
    7575if (badMemBlock(stderr, memBlock, file, lineo, func)) { \
    76     psMemBlockPrint(stderr, memBlock); \
    77     PS_MEM_ABORT(__func__, "Unsafe to Continue"); \
     76    PS_MEM_ABORT(__func__, "Unsafe to Continue\n"); \
    7877}
    7978
     
    155154    // p_psAlloc/p_psFree here.
    156155
    157     // ->nextBlock, & -> prevousBlock should not be looked at but this function
    158     // as they make be changed out from underneath us by new memory allocation
     156    bool bad = false;
     157    bool blockPrinted = false;
     158
    159159    if (memBlock == NULL) {
    160         fprintf(output, _("NULL memory block. Caught in %s at (%s:%d.)."), func, file, lineno);
     160        fprintf(output, _("NULL memory block.\n"
     161                          "Caught in %s at (%s:%d.).\n"), func, file, lineno);
     162        // return now as we can't do anything else
    161163        return true;
    162164    }
    163165
    164     if (memBlock->refCounter == 0) {
     166    if (memBlock->refCounter < 1) {
    165167        // using an unreferenced block of memory, are you?
    166         fprintf(output, _("Memory block was freed but still being used.  Caught in %s at (%s:%d)."), func, file, lineno);
    167         return true;
     168        psMemBlockPrint(output, memBlock);
     169        blockPrinted = true;
     170        fprintf(output, _("\n\tMemory block was freed but still being used.\n"));
     171        bad = true;
    168172    }
    169173
    170174    if (memBlock->startblock != P_PS_MEMMAGIC || memBlock->endblock != P_PS_MEMMAGIC) {
    171         fprintf(output, _("Memory block is corrupted; buffer underflow detected.Caught in %s at (%s:%d)."), func, file, lineno);
    172         return true;
    173     }
     175        if (!blockPrinted) {
     176            psMemBlockPrint(output, memBlock);
     177            blockPrinted = true;
     178        }
     179        fprintf(output, _("\n\tMemory block is corrupted; buffer underflow detected.\n"));
     180        bad = true;
     181    }
     182
    174183    if (*(psPtr *)((int8_t *) (memBlock + 1) + memBlock->userMemorySize) != P_PS_MEMMAGIC) {
    175         fprintf(output,
    176                 _("Memory block is corrupted; buffer overflow detected. Caught in %s at (%s:%d)."), func, file, lineno);
    177         return true;
    178     }
    179 
    180     return false;
     184        if (!blockPrinted) {
     185            psMemBlockPrint(output, memBlock);
     186            blockPrinted = true;
     187        }
     188        fprintf(output, _("\n\tMemory block is corrupted; buffer overflow detected.\n"));
     189        bad = true;
     190    }
     191
     192    //  XXX ->nextBlock, & -> prevousBlock really should not be looked at by
     193    //  this function as they may be changed out from underneath us by new
     194    //  memory allocation.  However, the memBlock itself shouldn't go away (end
     195    //  users responsiblity) so all we're really risking is a garbage value.
     196
     197    if (memBlock == memBlock->nextBlock) {
     198        if (!blockPrinted) {
     199            psMemBlockPrint(output, memBlock);
     200            blockPrinted = true;
     201        }
     202        fprintf(output, _("\n\tMemory block's ->nextBlock pointer refers to itself.\n"));
     203        bad = true;
     204    }
     205
     206    if (memBlock == memBlock->previousBlock) {
     207        if (!blockPrinted) {
     208            psMemBlockPrint(output, memBlock);
     209            blockPrinted = true;
     210        }
     211        fprintf(output, _("\n\tMemory block's ->previousBlock pointer refers to itself.\n"));
     212        bad = true;
     213    }
     214
     215    if (bad) {
     216        fprintf(output, _("\tCaught in %s at (%s:%d).\n"), func, file, lineno);
     217    }
     218
     219    return bad;
    181220}
    182221
     
    323362        if (badMemBlock(output, memBlock, __FILE__, __LINE__, __func__)) {
    324363            nbad++;
    325 
    326             psMemBlockPrint(output, memBlock);
    327364
    328365            if (abort_on_error) {
     
    458495        if (memBlock == NULL) {
    459496            MUTEX_UNLOCK(&memBlockListMutex);
     497            psMemBlockPrint(stderr,  ((psMemBlock *)ptr) - 1);
    460498            fprintf(stderr, "Problem reallocating block\n");
    461             psMemBlockPrint(stderr,  ((psMemBlock *)ptr) - 1);
    462499            PS_MEM_ABORT(__func__, "Failed to reallocate to %zd bytes at %s (%s:%d)", size, func, file, lineno);
    463500        }
     
    10761113{
    10771114    return fprintf(output,
    1078                    "Memory Block ID: %lu\n"
     1115                   "Memory Block ID: %lu @ %p\n"
    10791116                   "\tPrevious Block: %p Next Block: %p\n"
    10801117                   "\tFree function: %p\n"
     
    10831120                   "\tAllocated in %s at (%s:%d)\n"
    10841121                   "\t\tby Thread ID %lu\n",
    1085                    memBlock->id,
     1122                   memBlock->id, memBlock,
    10861123                   memBlock->previousBlock, memBlock->nextBlock,
    10871124                   memBlock->freeFunc,
    10881125                   memBlock->userMemorySize, memBlock->refCounter, (memBlock->persistent ? "Yes" : "No"),
    1089                    memBlock->startblock, memBlock->endblock, (memBlock + 1 + memBlock->userMemorySize),
     1126                   memBlock->startblock, memBlock->endblock,
     1127                   *(psPtr *)((int8_t *) (memBlock + 1) + memBlock->userMemorySize),
    10901128                   memBlock->func, memBlock->file, memBlock->lineno, memBlock->tid);
    10911129}
Note: See TracChangeset for help on using the changeset viewer.