]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/LeakFinder.cc
2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 /* DEBUG: section 45 Callback Data Registry */
12 * Use these to find memory leaks
19 #include "LeakFinder.h"
20 #include "SquidTime.h"
23 /* ========================================================================= */
25 LeakFinderPtr::LeakFinderPtr(void *p
, const char *f
, const int l
) :
30 // XXX: these bits should be done by hash_link()
35 /* ========================================================================= */
37 LeakFinder::LeakFinder() :
41 debugs(45, 3, "LeakFinder constructed");
42 table
= hash_create(cmp
, 1 << 8, hash
);
44 /* if this is desired to reinstate, add a
45 * RegisterWithCacheManager method
47 cachemgrRegister("leaks",
48 "Memory Leak Tracking",
54 LeakFinder::addSome(void *p
, const char *file
, int line
)
56 assert(hash_lookup(table
, p
) == NULL
);
57 LeakFinderPtr
*c
= new LeakFinderPtr(p
, file
, line
);
64 LeakFinder::touch(void *p
, const char *file
, int line
)
67 LeakFinderPtr
*c
= (LeakFinderPtr
*) hash_lookup(table
, p
);
71 c
->when
= squid_curtime
;
76 LeakFinder::freeSome(void *p
, const char *file
, int line
)
79 LeakFinderPtr
*c
= (LeakFinderPtr
*) hash_lookup(table
, p
);
81 hash_remove_link(table
, c
);
88 /* ========================================================================= */
91 LeakFinder::cmp(const void *p1
, const void *p2
)
93 return (char *) p1
- (char *) p2
;
97 LeakFinder::hash(const void *p
, unsigned int mod
)
99 return ((unsigned long) p
>> 8) % mod
;
108 if (squid_curtime
== last_dump
)
111 last_dump
= squid_curtime
;
113 debugs(45, DBG_IMPORTANT
, "Tracking " << count
<< " pointers");
119 while ((c
= (LeakFinderPtr
*)hash_next(table
))) {
120 debugs(45, DBG_IMPORTANT
, std::setw(20) << c
->key
<< " last used " << std::setw(9) << (squid_curtime
- c
->when
) <<
121 " seconds ago by " << c
->file
<< ":" << c
->line
);
125 #endif /* USE_LEAKFINDER */