diff options
Diffstat (limited to 'src/libstrongswan/utils/leak_detective.h')
-rw-r--r-- | src/libstrongswan/utils/leak_detective.h | 52 |
1 files changed, 45 insertions, 7 deletions
diff --git a/src/libstrongswan/utils/leak_detective.h b/src/libstrongswan/utils/leak_detective.h index 7a29e81d7..3fd0b8c93 100644 --- a/src/libstrongswan/utils/leak_detective.h +++ b/src/libstrongswan/utils/leak_detective.h @@ -24,6 +24,30 @@ typedef struct leak_detective_t leak_detective_t; #include <library.h> +#include <utils/backtrace.h> + +/** + * Callback function to report leak/usage information + * + * @param user user specific data + * @param count number of allocations + * @param bytes total size of allocations + * @param bt backtrace of allocation + * @param detailed TRUE to show a detailed backtrace + */ +typedef void (*leak_detective_report_cb_t)(void *user, int count, size_t bytes, + backtrace_t *bt, bool detailed); + +/** + * Callback function to report leak/usage summary information + * + * @param user user specific data + * @param count total number of allocations + * @param bytes total size of all reported allocations + * @param whitelisted number of allocations suppressed by whitelist + */ +typedef void (*leak_detective_summary_cb_t)(void* user, int count, size_t bytes, + int whitelisted); /** * Leak detective finds leaks and bad frees using malloc hooks. @@ -36,25 +60,39 @@ typedef struct leak_detective_t leak_detective_t; struct leak_detective_t { /** - * Report leaks to stderr. + * Report leaks to the registered callback functions. * * @param detailed TRUE to resolve line/filename of leak (slow) */ void (*report)(leak_detective_t *this, bool detailed); /** - * Number of detected leaks. + * Report current memory usage to out. + * Set callback functions invoked during a report(). * - * @return number of leaks + * @param cb callback invoked for each detected leak + * @param scb summary callback invoked at end of report + * @param user user data to supply to callbacks */ - int (*leaks)(leak_detective_t *this); + void (*set_report_cb)(leak_detective_t *this, leak_detective_report_cb_t cb, + leak_detective_summary_cb_t scb, void *user); /** - * Report current memory usage to out. + * Report current memory usage using a callbacks. + * + * @param cb callback invoked for each allocation + * @param scb summary callback invoked at end of usage report + * @param user user data supplied to callbacks + */ + void (*usage)(leak_detective_t *this, leak_detective_report_cb_t cb, + leak_detective_summary_cb_t scb, void *user); + + /** + * Number of detected leaks. * - * @param out target to write usage report to + * @return number of leaks */ - void (*usage)(leak_detective_t *this, FILE *out); + int (*leaks)(leak_detective_t *this); /** * Enable/disable leak detective hooks for the current thread. |