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) {
88 if (item->
use != NULL)
89 item->
use = yarnFreeLock(item->
use);
93 yarnRelease(pool->
have);
94 pool->
have = yarnFreeLock(pool->
have);
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;
123 pool->
have = yarnNewLock(0);
130 pool->
dbg = (
const char* (*)(
void*)) dbg;
144 const char * fn,
unsigned ln)
147 if (item == NULL)
return NULL;
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)
169 if (item == NULL)
return NULL;
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)
191 if (item == NULL)
return NULL;
194 assert(item->
pool != NULL);
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) {
207 if (pool != NULL && pool->
fini != NULL)
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);
231 if (pool->
head != NULL) {
234 if (pool->
head == NULL)
238 yarnTwist(pool->
have, BY, -1);
246 assert(pool->
limit != 0);
250 yarnRelease(pool->
have);
254 item->
use = yarnNewLock(0);
269 yarnPossess(pool->
have);
273 yarnTwist(pool->
have, BY, 1);
274 if (item->
use != NULL)
275 yarnTwist(item->
use, TO, 0);
279 if (item->
use != NULL) {
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);