IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 10, 2004, 3:57:54 PM (22 years ago)
Author:
desonia
Message:

p_realloc didn't track the last allocated buffer properly (if reallocating last buffer, it didn't reflect the pointer change in the global pointer for the last allocated buffer.

File:
1 edited

Legend:

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

    r474 r636  
    88 *  @author Robert Lupton, Princeton University
    99 *
    10  *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2004-04-20 03:10:31 $
     10 *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2004-05-11 01:57:54 $
    1212 *
    1313 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1919#include <stdlib.h>
    2020#include <stdio.h>
     21#include <stdbool.h>
     22
    2123#include "psMemory.h"
    2224#include "psError.h"
     
    4446static psMemExhaustedCallback memExhaustedCallback = memExhaustedCallbackDefault;
    4547
    46 psMemExhaustedCallback psMemExhaustedSetCallback(psMemExhaustedCallback func)
     48psMemExhaustedCallback psMemExhaustedCallbackSet(psMemExhaustedCallback func)
    4749{
    4850    psMemExhaustedCallback old = memExhaustedCallback;
     
    7880static psMemProblemCallback memProblemCallback = memProblemCallbackDefault;
    7981
    80 psMemProblemCallback psMemProblemSetCallback(psMemProblemCallback func)
     82psMemProblemCallback psMemProblemCallbackSet(psMemProblemCallback func)
    8183{
    8284    psMemProblemCallback old = memProblemCallback;
     
    140142static psMemFreeCallback memFreeCallback = memFreeCallbackDefault;
    141143
    142 psMemAllocateCallback psMemAllocateSetCallback(psMemAllocateCallback func)
     144psMemAllocateCallback psMemAllocateCallbackSet(psMemAllocateCallback func)
    143145{
    144146    psMemFreeCallback old = memAllocateCallback;
     
    199201
    200202    if (m->startblock != P_PS_MEMMAGIC || m->endblock != P_PS_MEMMAGIC) {
    201         psError(funcName, "psMemCheckCorruption: memory block %ld is corrupted", m->id);
     203        psError(funcName, "psMemCheckCorruption: memory block %ld is corrupted (%x %x)",
     204                m->id,m->startblock,m->endblock);
    202205        return(1);
    203206    }
     
    280283    } else {
    281284        psMemBlock *ptr = ((psMemBlock *)vptr) - 1;
     285        bool isBlockLast = false;
    282286
    283287        pthread_mutex_lock(&memBlockListMutex);
    284288
     289        isBlockLast = (ptr == lastMemBlockAllocated);
     290
    285291        ptr = (psMemBlock*)realloc(ptr, sizeof(psMemBlock) + size);
     292
     293        if (ptr == NULL) {
     294            psAbort(__func__, "Failed to reallocate %ld bytes at %s:%d",
     295                    size, file, lineno);
     296        }
     297
     298        if (isBlockLast) {
     299            lastMemBlockAllocated = ptr;
     300        }
    286301
    287302        // the block location may have changed, so fix the linked list addresses.
Note: See TracChangeset for help on using the changeset viewer.