12 #if defined(WITH_DMALLOC)
19 #if !defined(EXIT_FAILURE)
20 #define EXIT_FAILURE 1
26 fprintf(stderr,
_(
"memory alloc (%u bytes) returned NULL.\n"), (
unsigned)size);
49 const char * (*dbg) (
void *item)
79 yarnPossess(pool->
have);
80 while ((item = pool->
head) != NULL) {
82 if (item->
use != NULL)
83 item->
use = yarnFreeLock(item->
use);
87 yarnRelease(pool->
have);
88 pool->
have = yarnFreeLock(pool->
have);
91 assert(pool->
made == count);
93 if (pool->
made != count)
94 rpmlog(
RPMLOG_DEBUG,
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);
103 const char * (*dbg) (
void *item),
104 void (*init) (
void *item),
105 void (*fini) (
void *item))
109 pool->
have = yarnNewLock(0);
130 const char * fn,
unsigned ln)
133 if (item == NULL)
return NULL;
134 yarnPossess(item->
use);
135 if ((pool = item->
pool) != NULL && pool->
flags && msg != NULL) {
136 const char * imsg = (pool->
dbg ? (*pool->
dbg)((
void *)item) :
"");
138 fprintf(stderr,
"--> %s %p -- %ld %s at %s:%u%s\n", pool->
name,
139 item, yarnPeekLock(item->
use), msg, fn, ln, imsg);
142 yarnTwist(item->
use, BY, -1);
151 const char * fn,
unsigned ln)
154 if (item == NULL)
return NULL;
155 yarnPossess(item->
use);
156 if ((pool = item->
pool) != NULL && pool->
flags && msg != NULL) {
157 const char * imsg = (pool->
dbg ? (*pool->
dbg)((
void *)item) :
"");
159 fprintf(stderr,
"--> %s %p ++ %ld %s at %s:%u%s\n", pool->
name,
160 item, yarnPeekLock(item->
use)+1, msg, fn, ln, imsg);
163 yarnTwist(item->
use, BY, 1);
171 const char * msg,
const char * fn,
unsigned ln)
175 if (item == NULL)
return NULL;
178 assert(item->
pool != NULL);
180 yarnPossess(item->
use);
181 if ((pool = item->
pool) != NULL && pool->
flags && msg != NULL) {
182 const char * imsg = (pool->
dbg ? (*pool->
dbg)((
void *)item) :
"");
184 fprintf(stderr,
"--> %s %p -- %ld %s at %s:%u%s\n", pool->
name,
185 item, yarnPeekLock(item->
use), msg, fn, ln, imsg);
188 if (yarnPeekLock(item->
use) <= 1
L) {
189 if (pool != NULL && pool->
fini != NULL)
190 (*pool->
fini) ((
void *)item);
193 yarnTwist(item->
use, BY, -1);
195 return (
void *) item;
207 yarnPossess(pool->
have);
208 if (pool->
limit == 0)
209 yarnWaitFor(pool->
have, NOT_TO_BE, 0);
212 if (pool->
head != NULL) {
215 if (pool->
head == NULL)
219 yarnTwist(pool->
have, BY, -1);
224 assert(pool->
limit != 0);
228 yarnRelease(pool->
have);
232 item->
use = yarnNewLock(0);
243 if ((pool = item->
pool) != NULL) {
244 yarnPossess(pool->
have);
248 yarnTwist(pool->
have, BY, 1);
249 if (item->
use != NULL)
250 yarnTwist(item->
use, TO, 0);
254 if (item->
use != NULL) {
255 yarnTwist(item->
use, TO, 0);
256 item->
use = yarnFreeLock(item->
use);
263 #if !(HAVE_MCHECK_H && defined(__GNUC__)) && !defined(__LCLINT__)
267 register void *value;
268 if (size == 0) size++;
269 value = malloc (size);
277 register void *value;
278 if (size == 0) size++;
279 if (nmemb == 0) nmemb++;
280 value = calloc (nmemb, size);
288 register void *value;
289 if (size == 0) size++;
290 value = realloc (ptr, size);
298 size_t size = strlen(str) + 1;
299 char *newstr = (
char *) malloc (size);
301 newstr = (
char *)
vmefail(size);
302 strcpy (newstr, str);