Fix for bug 681: add debug version of realloc()
This commit was SVN r689.
Этот коммит содержится в:
родитель
e67c201a36
Коммит
d772d8db45
@ -57,5 +57,6 @@ typedef enum { false, true } bool;
|
||||
have Cascading Includes Of Death. */
|
||||
#include "lam/mem/malloc.h"
|
||||
#define malloc(size) lam_malloc((size), __FILE__, __LINE__)
|
||||
#define realloc(ptr, size) lam_realloc((ptr), (size), __FILE__, __LINE__)
|
||||
#define free(ptr) lam_free((ptr), __FILE__, __LINE__)
|
||||
#endif
|
||||
|
@ -68,18 +68,9 @@ void lam_malloc_finalize(void)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \internal
|
||||
*
|
||||
* Back-end error-checking malloc function for LAM (you should use the
|
||||
* LAM_MALLOC() macro instead of this function).
|
||||
*
|
||||
* @param size The number of bytes to allocate
|
||||
* @param file Typically the __FILE__ macro
|
||||
* @param line Typically the __LINE__ macro
|
||||
*
|
||||
* This function is only used when --enable-mem-debug was specified to
|
||||
* configure (or by default if you're building in a CVS checkout).
|
||||
|
||||
/*
|
||||
* Debug version of malloc
|
||||
*/
|
||||
void *lam_malloc(size_t size, char *file, int line)
|
||||
{
|
||||
@ -103,18 +94,40 @@ void *lam_malloc(size_t size, char *file, int line)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \internal
|
||||
*
|
||||
* Back-end error-checking free function for LAM (you should use
|
||||
* free() instead of this function).
|
||||
*
|
||||
* @param addr Address on the heap to free()
|
||||
* @param file Typically the __FILE__ macro
|
||||
* @param line Typically the __LINE__ macro
|
||||
*
|
||||
* This function is only used when --enable-mem-debug was specified to
|
||||
* configure (or by default if you're building in a CVS checkout).
|
||||
/*
|
||||
* Debug version of realloc
|
||||
*/
|
||||
void *lam_realloc(void *ptr, size_t size, char *file, int line)
|
||||
{
|
||||
void *addr;
|
||||
|
||||
if (lam_malloc_debug_level > 1) {
|
||||
if (size <= 0) {
|
||||
if (NULL == ptr) {
|
||||
lam_output(lam_malloc_output,
|
||||
"Realloc NULL for %ld bytes (%s, %d)",
|
||||
(long) size, file, line);
|
||||
} else {
|
||||
lam_output(lam_malloc_output, "Realloc %p for %ld bytes (%s, %d)",
|
||||
ptr, (long) size, file, line);
|
||||
}
|
||||
}
|
||||
}
|
||||
addr = realloc(ptr, size);
|
||||
if (lam_malloc_debug_level > 0) {
|
||||
if (NULL == addr) {
|
||||
lam_output(lam_malloc_output,
|
||||
"Realloc %p for %ld bytes failed (%s, %d)",
|
||||
ptr, (long) size, file, line);
|
||||
}
|
||||
}
|
||||
|
||||
return addr;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Debug version of free
|
||||
*/
|
||||
void lam_free(void *addr, char *file, int line)
|
||||
{
|
||||
@ -125,3 +138,4 @@ void lam_free(void *addr, char *file, int line)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -70,6 +70,22 @@ extern "C" {
|
||||
*/
|
||||
void *lam_malloc(size_t size, char *file, int line);
|
||||
|
||||
/**
|
||||
* \internal
|
||||
*
|
||||
* Back-end error-checking realloc function for LAM (you should use
|
||||
* the normal realloc() instead of this function).
|
||||
*
|
||||
* @param ptr Pointer to reallocate
|
||||
* @param size The number of bytes to allocate
|
||||
* @param file Typically the __FILE__ macro
|
||||
* @param line Typically the __LINE__ macro
|
||||
*
|
||||
* This function is only used when --enable-mem-debug was specified to
|
||||
* configure (or by default if you're building in a CVS checkout).
|
||||
*/
|
||||
void *lam_realloc(void *ptr, size_t size, char *file, int line);
|
||||
|
||||
/**
|
||||
* \internal
|
||||
*
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user