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)
83 yarnPossess(pool->
have);
85 while ((item = pool->
head) !=
NULL) {
89 item->
use = yarnFreeLock(item->
use);
93 yarnRelease(pool->
have);
94 pool->
have = yarnFreeLock(pool->
have);
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;
123 pool->
have = yarnNewLock(0);
130 pool->
dbg = (
const char* (*)(
void*)) dbg;
144 const char *
fn,
unsigned ln)
148 yarnPossess(item->
use);
151 const char * imsg = (pool->
dbg ? (*pool->
dbg)((
void *)item) :
"");
153 fprintf(stderr,
"--> %s %p -- %ld %s at %s:%u%s\n", pool->
name,
154 item, yarnPeekLock(item->
use), msg, fn, ln, imsg);
157 yarnTwist(item->
use, BY, -1);
166 const char *
fn,
unsigned ln)
170 yarnPossess(item->
use);
172 const char * imsg = (pool->
dbg ? (*pool->
dbg)((
void *)item) :
"");
174 fprintf(stderr,
"--> %s %p ++ %ld %s at %s:%u%s\n", pool->
name,
175 item, yarnPeekLock(item->
use)+1, msg, fn, ln, imsg);
179 yarnTwist(item->
use, BY, 1);
187 const char *
msg,
const char *
fn,
unsigned ln)
196 yarnPossess(item->
use);
199 const char * imsg = (pool->
dbg ? (*pool->
dbg)((
void *)item) :
"");
201 fprintf(stderr,
"--> %s %p -- %ld %s at %s:%u%s\n", pool->
name,
202 item, yarnPeekLock(item->
use), msg, fn, ln, imsg);
205 if (yarnPeekLock(item->
use) <= 1
L) {
208 (*pool->
fini) ((
void *)item);
212 yarnTwist(item->
use, BY, -1);
214 return (
void *) item;
226 yarnPossess(pool->
have);
227 if (pool->
limit == 0)
228 yarnWaitFor(pool->
have, NOT_TO_BE, 0);
238 yarnTwist(pool->
have, BY, -1);
250 yarnRelease(pool->
have);
254 item->
use = yarnNewLock(0);
269 yarnPossess(pool->
have);
273 yarnTwist(pool->
have, BY, 1);
275 yarnTwist(item->
use, TO, 0);
280 yarnTwist(item->
use, TO, 0);
281 item->
use = yarnFreeLock(item->
use);
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);
rpmlog(RPMLOG_ERR,"%s\n", buf)
char * xstrdup(const char *str)
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)
void * rpmioFreePoolItem(rpmioItem item, const char *msg, const char *fn, unsigned ln)
Free a pool item.
#define VALGRIND_MEMPOOL_FREE(pool, addr)
#define VALGRIND_CREATE_MEMPOOL(pool, rzB, is_zeroed)
Yet Another syslog(3) API clone.
void * xcalloc(size_t nmemb, size_t size)
assert(key->size==sizeof(hdrNum))
rpmioItem rpmioGetPool(rpmioPool pool, size_t size)
Get unused item from pool, or alloc a new item.
fprintf(stderr,"--> %s(%p,%p,%p) sig %p sigp %p\n", __FUNCTION__, dig, t, rsactx, sig, sigp)
struct yarnLock_s * yarnLock
rpmioItem rpmioPutPool(rpmioItem item)
Put unused item into pool (or free).
#define VALGRIND_DESTROY_MEMPOOL(pool)
struct rpmioItem_s * rpmioItem
rpmioItem rpmioUnlinkPoolItem(rpmioItem item, const char *msg, const char *fn, unsigned ln)
Decrement a pool item refcount.
void * vmefail(size_t size)
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.
#define ANNOTATE_HAPPENS_BEFORE(_obj)
#define VALGRIND_HG_CLEAN_MEMORY(_qzz_start, _qzz_len)
struct rpmioPool_s * rpmioPool
static void
Print copy of spec file, filling in Group/Description/Summary from specspo.
#define VALGRIND_MEMPOOL_ALLOC(pool, addr, size)
#define ANNOTATE_HAPPENS_AFTER(_obj)
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
rpmioPool rpmioFreePool(rpmioPool pool)
Reclaim memory pool items.