Add getter for the number of leaks to leak_detective_t
authorTobias Brunner <tobias@strongswan.org>
Tue, 4 Jun 2013 14:21:48 +0000 (16:21 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 11 Jun 2013 09:03:13 +0000 (11:03 +0200)
src/libstrongswan/utils/leak_detective.c
src/libstrongswan/utils/leak_detective.h

index 4f3c9f7..9d90622 100644 (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,
index 55d7e44..6a39aef 100644 (file)
@@ -43,6 +43,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.
         *
         * @param out                   target to write usage report to