summaryrefslogtreecommitdiff
path: root/nDPId-test.c
diff options
context:
space:
mode:
Diffstat (limited to 'nDPId-test.c')
-rw-r--r--nDPId-test.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/nDPId-test.c b/nDPId-test.c
index d2198cdf4..e77846c67 100644
--- a/nDPId-test.c
+++ b/nDPId-test.c
@@ -4,6 +4,8 @@
#include <unistd.h>
static void nDPIsrvd_memprof_log(char const * const format, ...);
+static void nDPIsrvd_memprof_log_alloc(size_t alloc_size);
+static void nDPIsrvd_memprof_log_free(size_t free_size);
#define NO_MAIN 1
#include "utils.c"
@@ -128,6 +130,10 @@ static pthread_mutex_t nDPId_start_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t nDPIsrvd_start_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t distributor_start_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t log_mutex = PTHREAD_MUTEX_INITIALIZER;
+static unsigned long long int nDPIsrvd_alloc_count = 0;
+static unsigned long long int nDPIsrvd_alloc_bytes = 0;
+static unsigned long long int nDPIsrvd_free_count = 0;
+static unsigned long long int nDPIsrvd_free_bytes = 0;
#define THREAD_ERROR(thread_arg) \
do \
@@ -154,6 +160,18 @@ static void nDPIsrvd_memprof_log(char const * const format, ...)
va_end(ap);
}
+void nDPIsrvd_memprof_log_alloc(size_t alloc_size)
+{
+ nDPIsrvd_alloc_count++;
+ nDPIsrvd_alloc_bytes += alloc_size;
+}
+
+void nDPIsrvd_memprof_log_free(size_t free_size)
+{
+ nDPIsrvd_free_count++;
+ nDPIsrvd_free_bytes += free_size;
+}
+
static int setup_pipe(int pipefd[PIPE_FDS])
{
if (pipe(pipefd) != 0)
@@ -1103,6 +1121,13 @@ int main(int argc, char ** argv)
return 1;
}
+ if (nDPIsrvd_alloc_bytes != nDPIsrvd_free_bytes || nDPIsrvd_alloc_count != nDPIsrvd_free_count)
+ {
+ logger(1, "%s: %s", argv[0], "nDPIsrvd.h memory leak detected.");
+ logger(1, "%s: Allocated / Free'd bytes: %llu / %llu", argv[0], nDPIsrvd_alloc_bytes, nDPIsrvd_free_bytes);
+ logger(1, "%s: Allocated / Free'd count: %llu / %llu", argv[0], nDPIsrvd_alloc_count, nDPIsrvd_free_count);
+ }
+
if (nDPId_return.cur_active_flows != 0 || nDPId_return.cur_idle_flows != 0)
{
logger(1,