2
* Copyright (C) 2004,2005 Heinz Mauelshagen, Red Hat GmbH.
5
* See file LICENSE at the top of this source tree for license information.
10
#include <sys/types.h>
12
#include "dbg_malloc.h"
16
__dbg_malloc(size_t size, int init)
18
void *ret = malloc(size);
29
_dbg_malloc(size_t size, struct lib_context *lc,
30
const char *who, unsigned int line)
32
void *ret = __dbg_malloc(size, 1);
34
log_dbg(lc, "%s: dbg_malloc(%zu) at line %u returned 0x%x",
35
(char *) who, size, line, (unsigned long) ret);
41
_dbg_realloc(void *ptr, size_t size, struct lib_context *lc,
42
const char *who, unsigned int line)
44
void *ret = realloc(ptr, size);
46
log_dbg(lc, "%s: dbg_realloc(0x%x, %zu) at line %u returned 0x%x",
47
(char *) who, (unsigned long) ptr, size, line,
54
_dbg_strndup(void *ptr, size_t len, struct lib_context *lc,
55
const char *who, unsigned int line)
59
if ((ret = __dbg_malloc(len + 1, 0))) {
61
strncpy(ret, ptr, len);
64
log_dbg(lc, "%s: dbg_strndup(0x%x) at line %u returned 0x%x",
65
(char *) who, (unsigned long) ptr, line, (unsigned long) ret);
72
_dbg_strdup(void *ptr, struct lib_context *lc,
73
const char *who, unsigned int line)
75
return _dbg_strndup(ptr, strlen(ptr), lc, who, line);
80
_dbg_free(void *ptr, struct lib_context *lc, const char *who, unsigned int line)
82
log_dbg(lc, "%s: dbg_free(0x%x) at line %u",
83
(char *) who, (unsigned long) ptr, line);
90
_dbg_malloc(size_t size)
92
return __dbg_malloc(size, 1);
96
_dbg_realloc(void *ptr, size_t size)
98
return realloc(ptr, size);
102
_dbg_strndup(void *ptr, size_t len)
106
if ((ret = __dbg_malloc(len + 1, 0))) {
108
strncpy(ret, ptr, len);
115
_dbg_strdup(void *ptr)
117
return _dbg_strndup(ptr, strlen(ptr));
126
#endif /* #ifdef DEBUG_MALLOC */