示例#1
0
void *xrealloc (void *ptr, size_t bytes)
#endif
{
    void *cp;

	MALLOC_CHECK();
#ifdef _DEBUG
    if (!ptr)
		cp = _malloc_dbg(bytes?bytes:1,_NORMAL_BLOCK,file,line);
	else
		cp = _realloc_dbg(ptr, bytes,_NORMAL_BLOCK,file,line);
#else
    if (!ptr)
		cp = malloc (bytes?bytes:1);
	else
		cp = realloc(ptr, bytes);
#endif

    if (cp == NULL)
    {
		char buf[80];
		sprintf (buf, "out of memory; can not reallocate %lu bytes",
			(unsigned long) bytes);
		error (1, 0, buf);
    }
	MALLOC_CHECK();
    return (cp);
}
示例#2
0
文件: misc.c 项目: zhangzm/EnvTool
/*
 * A realloc() that fails if no memory. It's pretty hopeless to continue
 * this program if realloc() fails.
 */
void *realloc_at (void *ptr, size_t size, const char *file, unsigned line)
{
  struct mem_head *head = (struct mem_head*) ptr;
  void  *p;

  size += sizeof(*head);

#if defined(_CRTDBG_MAP_ALLOC)  /* cl -MDd .. */
  p = _realloc_dbg (head, size, _NORMAL_BLOCK, file, line);
#else
  p = realloc (head, size);
#endif

  if (!p)
     FATAL ("realloc() failed at %s, line %u\n", file, line);

  head->marker = MEM_MARKER;
  head->size   = size;
  if (p != head)
  {
    del_from_mem_list (p);
    add_to_mem_list (head, file, line);
    mem_max += size;
    mem_allocs++;
  }
  return (p);
}
示例#3
0
void *CDbgMemAlloc::Realloc( void *pMem, size_t nSize, const char *pFileName, int nLine )
{
/*	GetActualDbgInfo( pFileName, nLine );

	int nOldSize = GetSize( pMem );
	const char *pOldFileName = GetAllocatonFileName( pMem );
	int oldLine = GetAllocatonLineNumber( pMem );

	if ( pMem != 0 )
	{
		RegisterDeallocation( FindOrCreateEntry( pOldFileName, oldLine ), nOldSize, 0 );
		RegisterDeallocation( m_GlobalInfo, nOldSize, 0 );
	}
*/
//	m_Timer.Start();
	pMem = _realloc_dbg( pMem, nSize, _NORMAL_BLOCK, pFileName, nLine );
//	m_Timer.End();
	
//	unsigned long nTime = m_Timer.GetDuration().GetMicroseconds();

//	RegisterAllocation( FindOrCreateEntry( pFileName, nLine ), nSize, nTime );
//	RegisterAllocation( m_GlobalInfo, nSize, nTime );

	return pMem;
}
示例#4
0
void* BioAPI _BioAPI_realloc(void* ptr, uint32 size, void* ref,
							const char * szFilename, uint32 u32LineNumber)
{
#ifdef _DEBUG
	return _realloc_dbg( ptr, size, _NORMAL_BLOCK, szFilename, u32LineNumber );
#else
	return realloc( ptr, size );
#endif
}
示例#5
0
void *_vm_realloc(void *ptr, size_t size, const memory::quiet_alloc_t &, const char *filename, int line)
{
	auto ret_ptr = _realloc_dbg(ptr, size, _NORMAL_BLOCK, filename, line);

	if (ret_ptr == nullptr)
	{
		mprintf(("Malloc failed!!!!!!!!!!!!!!!!!!!\n"));
	}

	return ret_ptr;
}
示例#6
0
void* utRealloc(void* ptr, size_t size, const char* file, int line)
{
	my_reallocCount++;
	if (my_reallocHandler)
		return my_reallocHandler(ptr, size, file, line);

#if defined(CRTDBG_MAP_ALLOC)
	return _realloc_dbg(ptr, size, _NORMAL_BLOCK, file, line);
#else
	return realloc(ptr, size);
#endif
}
示例#7
0
void allocRealloc(bool bFree)
{
    int* temp = (int*)malloc(17);
    int* old_leaked_memory = (int*)realloc(temp, 23);
    int* leaked_memory = (int*)_recalloc(old_leaked_memory, 1, 31);
    int* old_leaked_memory_dbg = (int*)malloc(9);
    int* leaked_memory_dbg = (int*)_realloc_dbg(old_leaked_memory_dbg, 21, _NORMAL_BLOCK, __FILE__, __LINE__);
    if (bFree)
    {
        free(leaked_memory);
        _free_dbg(leaked_memory_dbg, _NORMAL_BLOCK);
    }
}
示例#8
0
文件: Ram.c 项目: 5432935/genesis3d
GENESISAPI     void * _geRam_DebugRealloc (void *ptr, uint32 newsize, const char* pFile, int line)
    {
        char *p;
        char * NewPtr;
        uint32 size;

        // if realloc is called with NULL, just treat it like an alloc
        if (ptr == NULL)
        {
            return _geRam_DebugAllocate(newsize, pFile, line);
        }

        // verify the block
        p = ram_verify_block (ptr);
        if (p == NULL)
        {
            return NULL;
        }

        // if newsize is NULL, then it's a free and return NULL
        if (newsize == 0)
        {
            geRam_Free (ptr);
            return NULL;
        }

        // gotta get the size before I realloc it...
        size = *((uint32 *)p);

        do
        {
            NewPtr = (char *)_realloc_dbg(p, newsize+EXTRA_SIZE, _NORMAL_BLOCK, pFile, line);
        } while ((NewPtr == NULL) && geRam_DoCriticalCallback ());

        // if allocation failed, return NULL...
        if (NewPtr == NULL)
        {
            return NULL;
        }

        geRam_SetupBlock (NewPtr, newsize, DONT_INITIALIZE);

        geRam_CurrentlyUsed += (newsize - size);
        if (geRam_CurrentlyUsed > geRam_MaximumUsed)
        {
            geRam_MaximumUsed = geRam_CurrentlyUsed;
        }
        assert ((geRam_CurrentlyUsed >= 0) && "free()d more ram than you allocated!");

        return NewPtr + HEADER_SIZE;
    }
void* ReallocMemory(void* memory, size_t size) {
    if (memory == NULL) {
        return AllocMemory(size);
    }
    if (size == 0) {
        FreeMemory(memory);
        return NULL;
    }
#if defined(_WIN32) && !defined(NDEBUG)
    return _realloc_dbg(memory, size, _NORMAL_BLOCK, __FILE__, __LINE__);
#else
    return realloc(memory, size);
#endif
}
示例#10
0
文件: m_alloc.cpp 项目: Gaerzi/SLADE
void *M_Realloc_Dbg(void *memblock, size_t size, const char *file, int lineno)
{
	if (memblock != NULL)
	{
		GC::AllocBytes -= _msize(memblock);
	}
	void *block = _realloc_dbg(memblock, size, _NORMAL_BLOCK, file, lineno);
	if (block == NULL)
	{
		I_FatalError("Could not realloc %zu bytes", size);
	}
	GC::AllocBytes += _msize(block);
	return block;
}
示例#11
0
文件: Mem.cpp 项目: AnnaGarrett/coho
//=============================================================================
void *  MemRealloc (void * ptr, size_t bytes, const char file[], int line) {
#ifdef USE_MALLOC
    if (void * result = _realloc_dbg(ptr, bytes, _NORMAL_BLOCK, file, line))
        return result;
#else
    REF(file);
    REF(line);
    if (!s_heap)
        s_heap = GetProcessHeap();

    if (void * result = HeapReAlloc(s_heap, 0, ptr, bytes))
        return result;
#endif
    OutOfMemory();
    return NULL;
}
示例#12
0
void *_vm_realloc( void *ptr, int size, int quiet )
#endif
{
	// if this is the first time it's used then we need to malloc it first
	if (ptr == NULL)
		return vm_malloc(size);

	void* ret_ptr = NULL;

#ifndef NDEBUG
	// Unregistered the previous allocation
	_CrtMemBlockHeader* phd = pHdr(ptr);
	int nSize = phd->nDataSize;

	TotalRam -= nSize;
	if (Cmdline_show_mem_usage)
		unregister_malloc(filename, nSize, ptr);
#endif

	ret_ptr = _realloc_dbg(ptr, size, _NORMAL_BLOCK, __FILE__, __LINE__);

	if (ret_ptr == NULL)
	{
		mprintf(("realloc failed!!!!!!!!!!!!!!!!!!!\n"));

		if (quiet && (size > 0) && (ptr != NULL))
		{
			// realloc doesn't touch the original ptr in the case of failure so we could still use it
			return NULL;
		}

		Error(LOCATION, "Out of memory.  Try closing down other applications, increasing your\n"
			"virtual memory size, or installing more physical RAM.\n");
	}
#ifndef	NDEBUG
	TotalRam += size;

	// register this allocation
	if (Cmdline_show_mem_usage)
		register_malloc(size, filename, line, ret_ptr);
#endif
	return ret_ptr;
}
示例#13
0
PTR MemReallocReal( PTR ptr, UINT32 uiSize, const STR8 pcFile, INT32 iLine )
{
	PTR	ptrNew;
	UINT32 uiOldSize = 0;


	if ( !fMemManagerInit )
	DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("MemRealloc: Warning -- Memory manager not initialized -- Line %d in %s", iLine, pcFile) );

	if(ptr != NULL)
	{
		uiOldSize = _msize(ptr);
		guiMemTotal -= uiOldSize;
		guiMemFreed += uiOldSize;
	MemDebugCounter--;
	}

	// Note that the ptr changes to ptrNew...
	ptrNew = _realloc_dbg( ptr, uiSize, _NORMAL_BLOCK, pcFile, iLine );
	if (ptrNew == NULL)
	{
		DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("MemReAlloc failed: ptr %d, %d->%d bytes (line %d file %s)", ptr, uiOldSize, uiSize, iLine, pcFile) );
		if ( uiSize != 0 )
		{
			// ptr is left untouched, so undo the math above
			guiMemTotal += uiOldSize;
			guiMemFreed -= uiOldSize;
			MemDebugCounter++;
		}
	}
	else
	{
#ifdef DEBUG_MEM_LEAKS
		DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_1, String("MemRealloc %p: Resizing %d bytes to %d bytes (line %d file %s) - New ptr %p", ptr, uiOldSize, uiSize, iLine, pcFile, ptrNew ) );
#endif

		guiMemTotal	+= uiSize;
		guiMemAlloced += uiSize;
		MemDebugCounter++;
	}

	return( ptrNew );
}
示例#14
0
文件: m_alloc.cpp 项目: Gaerzi/SLADE
void *M_Realloc_Dbg(void *memblock, size_t size, const char *file, int lineno)
{
	if(memblock == NULL)
		return M_Malloc_Dbg(size, file, lineno);

	if (memblock != NULL)
	{
		GC::AllocBytes -= _msize(memblock);
	}
	void *block = _realloc_dbg(((size_t*) memblock)-1, size+sizeof(size_t), _NORMAL_BLOCK, file, lineno);

	if (block == NULL)
	{
		I_FatalError("Could not realloc %zu bytes", size);
	}

	size_t *sizeStore = (size_t *) block;
	*sizeStore = size;
	block = sizeStore+1;

	GC::AllocBytes += _msize(block);
	return block;
}
示例#15
0
文件: osip_port.c 项目: avis/osip
void *_osip_realloc(void *ptr, size_t size, char *file, unsigned short line)
{
	return _realloc_dbg( ptr, size, _NORMAL_BLOCK, file, line );
}
示例#16
0
/* Shared by apr_app.c and start.c 
 *
 * An internal apr function to convert an array of strings (either
 * a counted or NULL terminated list, such as an argv[argc] or env[]
 * list respectively) from wide Unicode strings to narrow utf-8 strings.
 * These are allocated from the MSVCRT's _CRT_BLOCK to trick the system
 * into trusting our store.
 */
int apr_wastrtoastr(char const * const * *retarr, 
                    wchar_t const * const *arr, int args)
{
    apr_size_t elesize = 0;
    char **newarr;
    char *elements;
    char *ele;
    int arg;

    if (args < 0) {
        for (args = 0; arr[args]; ++args)
            ;
    }

    newarr = _malloc_dbg((args + 1) * sizeof(char *),
                         _CRT_BLOCK, __FILE__, __LINE__);

    for (arg = 0; arg < args; ++arg) {
        newarr[arg] = (void*)(wcslen(arr[arg]) + 1);
        elesize += (apr_size_t)newarr[arg];
    }

    /* This is a safe max allocation, we will realloc after
     * processing and return the excess to the free store.
     * 3 ucs bytes hold any single wchar_t value (16 bits)
     * 4 ucs bytes will hold a wchar_t pair value (20 bits)
     */
    elesize = elesize * 3 + 1;
    ele = elements = _malloc_dbg(elesize * sizeof(char), 
                                 _CRT_BLOCK, __FILE__, __LINE__);

    for (arg = 0; arg < args; ++arg) {
        apr_size_t len = (apr_size_t)newarr[arg];
        apr_size_t newlen = elesize;

        newarr[arg] = ele;
        (void)apr_conv_ucs2_to_utf8(arr[arg], &len,
                                    newarr[arg], &elesize);

        newlen -= elesize;
        ele += newlen;
        assert(elesize && (len == 0));
    }

    newarr[arg] = NULL;
    *(ele++) = '\0';

    /* Return to the free store if the heap realloc is the least bit optimized
     */
    ele = _realloc_dbg(elements, ele - elements, 
                       _CRT_BLOCK, __FILE__, __LINE__);

    if (ele != elements) {
        apr_size_t diff = ele - elements;
        for (arg = 0; arg < args; ++arg) {
            newarr[arg] += diff;
        }
    }

    *retarr = newarr;
    return args;
}