16 #if defined(WITH_DMALLOC)
23 #if !defined(EXIT_FAILURE)
24 #define EXIT_FAILURE 1
30 fprintf(stderr,
_(
"memory alloc (%u bytes) returned NULL.\n"), (
unsigned)size);
53 const char * (*dbg) (
void *item)
85 while ((item = pool->
head) != NULL) {
88 if (item->
use != NULL)
97 assert(pool->
made == count);
99 if (pool->
made != count)
100 rpmlog(
RPMLOG_WARNING,
D_(
"pool %s: FIXME: made %d, count %d\nNote: This is a harmless memory leak discovered while exiting, relax ...\n"), pool->
name, pool->
made, count);
110 char * (*dbg) (
void *item),
111 void (*init) (
void *item),
112 void (*fini) (
void *item))
116 #if defined(WITH_VALGRIND)
118 static int is_zeroed = 0;
120 is_zeroed = is_zeroed;
130 pool->
dbg = (
const char* (*)(
void*)) dbg;
144 const char * fn,
unsigned ln)
147 if (item == NULL)
return NULL;
151 const char * imsg = (pool->
dbg ? (*pool->
dbg)((
void *)item) :
"");
153 fprintf(stderr,
"--> %s %p -- %ld %s at %s:%u%s\n", pool->
name,
166 const char * fn,
unsigned ln)
169 if (item == NULL)
return NULL;
172 const char * imsg = (pool->
dbg ? (*pool->
dbg)((
void *)item) :
"");
174 fprintf(stderr,
"--> %s %p ++ %ld %s at %s:%u%s\n", pool->
name,
187 const char * msg,
const char * fn,
unsigned ln)
191 if (item == NULL)
return NULL;
194 assert(item->
pool != NULL);
199 const char * imsg = (pool->
dbg ? (*pool->
dbg)((
void *)item) :
"");
201 fprintf(stderr,
"--> %s %p -- %ld %s at %s:%u%s\n", pool->
name,
207 if (pool != NULL && pool->
fini != NULL)
208 (*pool->
fini) ((
void *)item);
214 return (
void *) item;
227 if (pool->
limit == 0)
231 if (pool->
head != NULL) {
234 if (pool->
head == NULL)
246 assert(pool->
limit != 0);
274 if (item->
use != NULL)
279 if (item->
use != NULL) {
288 #if !(HAVE_MCHECK_H && defined(__GNUC__)) && !defined(__LCLINT__)
292 register void *value;
293 if (size == 0) size++;
294 value = malloc (size);
302 register void *value;
303 if (size == 0) size++;
304 if (nmemb == 0) nmemb++;
305 value = calloc (nmemb, size);
313 register void *value;
314 if (size == 0) size++;
315 value = realloc (ptr, size);
323 size_t size = strlen(str) + 1;
324 char *newstr = (
char *) malloc (size);
326 newstr = (
char *)
vmefail(size);
327 strcpy (newstr, str);
void yarnTwist(yarnLock bolt, yarnTwistOP op, long val)
void yarnPossess(yarnLock bolt)
long yarnPeekLock(yarnLock bolt)
rpmioItem rpmioLinkPoolItem(rpmioItem item, const char *msg, const char *fn, unsigned ln)
Increment a pool item refcount.
static rpmioPool _rpmioPool
const char *(* dbg)(void *item)
static void rpmlog(int code, const char *fmt,...)
#define VALGRIND_MEMPOOL_FREE(pool, addr)
#define VALGRIND_CREATE_MEMPOOL(pool, rzB, is_zeroed)
void * xrealloc(void *ptr, size_t size)
Yet Another syslog(3) API clone.
void yarnWaitFor(yarnLock bolt, yarnWaitOP op, long val)
struct rpmioPool_s * rpmioPool
yarnLock yarnNewLock(long initial)
const char const bson const bson int limit
yarnLock yarnFreeLock(yarnLock bolt)
#define VALGRIND_DESTROY_MEMPOOL(pool)
void * rpmioFreePoolItem(rpmioItem item, const char *msg, const char *fn, unsigned ln)
Free a pool item.
void * xmalloc(size_t size)
rpmioItem rpmioUnlinkPoolItem(rpmioItem item, const char *msg, const char *fn, unsigned ln)
Decrement a pool item refcount.
const char const bson int mongo_write_concern int flags
void yarnRelease(yarnLock bolt)
rpmioPool rpmioNewPool(const char *name, size_t size, int limit, int flags, char *(*dbg)(void *item), void(*init)(void *item), void(*fini)(void *item))
Create a memory pool.
rpmioItem rpmioPutPool(rpmioItem item)
Put unused item into pool (or free).
rpmioItem rpmioGetPool(rpmioPool pool, size_t size)
Get unused item from pool, or alloc a new item.
struct rpmioItem_s * rpmioItem
const char const char size_t size
#define ANNOTATE_HAPPENS_BEFORE(_obj)
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
#define VALGRIND_HG_CLEAN_MEMORY(_qzz_start, _qzz_len)
#define VALGRIND_MEMPOOL_ALLOC(pool, addr, size)
#define ANNOTATE_HAPPENS_AFTER(_obj)
rpmioPool rpmioFreePool(rpmioPool pool)
Reclaim memory pool items.
void * vmefail(size_t size)
void * xcalloc(size_t nmemb, size_t size)
char * xstrdup(const char *str)