Add getter for the number of leaks to leak_detective_t

This commit is contained in:
Tobias Brunner
2013-06-11 11:03:13 +02:00
parent 80d9a9b722
commit 01e15ab5c7
2 changed files with 23 additions and 2 deletions
+16 -2
View File
@@ -589,7 +589,7 @@ static int print_traces(private_leak_detective_t *this,
enumerator = entries->create_enumerator(entries);
while (enumerator->enumerate(enumerator, NULL, &entry))
{
if (!thresh || entry->bytes >= thresh)
if (out && (!thresh || entry->bytes >= thresh))
{
fprintf(out, "%d bytes total, %d allocations, %d bytes average:\n",
entry->bytes, entry->count, entry->bytes / entry->count);
@@ -609,7 +609,7 @@ METHOD(leak_detective_t, report, void,
{
if (lib->leak_detective)
{
int leaks = 0, whitelisted = 0;
int leaks, whitelisted = 0;
leaks = print_traces(this, stderr, 0, detailed, &whitelisted);
switch (leaks)
@@ -632,6 +632,19 @@ METHOD(leak_detective_t, report, void,
}
}
METHOD(leak_detective_t, leaks, int,
private_leak_detective_t *this)
{
if (lib->leak_detective)
{
int leaks, whitelisted = 0;
leaks = print_traces(this, NULL, 0, FALSE, &whitelisted);
return leaks;
}
return 0;
}
METHOD(leak_detective_t, set_state, bool,
private_leak_detective_t *this, bool enable)
{
@@ -885,6 +898,7 @@ leak_detective_t *leak_detective_create()
INIT(this,
.public = {
.report = _report,
.leaks = _leaks,
.usage = _usage,
.set_state = _set_state,
.destroy = _destroy,
+7
View File
@@ -42,6 +42,13 @@ struct leak_detective_t {
*/
void (*report)(leak_detective_t *this, bool detailed);
/**
* Number of detected leaks.
*
* @return number of leaks
*/
int (*leaks)(leak_detective_t *this);
/**
* Report current memory usage to out.
*