IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 27, 2007, 1:14:35 PM (19 years ago)
Author:
jhoblitt
Message:

add psMemIsAlloced()

File:
1 edited

Legend:

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

    r12886 r14676  
    1010*  @author Joshua Hoblitt, University of Hawaii
    1111*
    12 *  @version $Revision: 1.96 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2007-04-18 19:38:10 $
     12*  @version $Revision: 1.97 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2007-08-27 23:14:35 $
    1414*
    1515*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    374374                MUTEX_UNLOCK(&memBlockListMutex);
    375375                PS_MEM_ABORT(__func__, "Detected memory corruption");
    376                 return nbad;
    377376            }
    378377        }
     
    383382
    384383    return nbad;
     384}
     385
     386bool p_psMemIsAlloced(const char *file,
     387                      unsigned int lineno,
     388                      const char *func,
     389                      const void *ptr)
     390{
     391    // if ptr is a psAlloc()'d memory, find the actual address of the memBlock
     392    psMemBlock *addr = ((psMemBlock *)ptr) - 1;
     393
     394    // get exclusive access to the memBlock list to avoid it changing on us
     395    // while we use it.
     396    MUTEX_LOCK(&memBlockListMutex);
     397
     398    // loop through the linked list of memBlocks looking for a matching pointer
     399    for (psMemBlock *memBlock = lastMemBlockAllocated; memBlock != NULL; memBlock = memBlock->nextBlock) {
     400        if (memBlock == addr) {
     401            // we found the memBlock
     402            HANDLE_BAD_BLOCK(memBlock, file, lineno, func);
     403
     404            MUTEX_UNLOCK(&memBlockListMutex);
     405            return true;
     406        }
     407    }
     408
     409    // release the lock on the memblock list
     410    MUTEX_UNLOCK(&memBlockListMutex);
     411
     412    return false;
    385413}
    386414
Note: See TracChangeset for help on using the changeset viewer.