From 9685885afe903a7c2e1f5774aaea5bc9d25b7958 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Thu, 9 May 2019 11:39:03 +0200 Subject: [PATCH] Tracking memory leaks is improving --- src/algo_rr.c | 5 +++++ src/algo_utils.c | 2 ++ src/donar_init.c | 2 +- src/proxy.c | 2 +- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/algo_rr.c b/src/algo_rr.c index 0c4381c..3f33018 100644 --- a/src/algo_rr.c +++ b/src/algo_rr.c @@ -306,6 +306,10 @@ int algo_rr_on_err(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) { return 0; } +void algo_rr_free(void* v) { + struct rr_ctx* rr = v; + free(rr); +} void algo_rr_init(struct evt_core_ctx* ctx, struct algo_ctx* app_ctx, struct algo_params* ap) { struct rr_ctx* rr = malloc(sizeof(struct rr_ctx)); @@ -321,6 +325,7 @@ void algo_rr_init(struct evt_core_ctx* ctx, struct algo_ctx* app_ctx, struct alg rr->recv_id = 0; rr->recv_id_late = 0; app_ctx->misc = rr; + app_ctx->free_misc = algo_rr_free; init_timer(ctx); } diff --git a/src/algo_utils.c b/src/algo_utils.c index 0478826..91d1742 100644 --- a/src/algo_utils.c +++ b/src/algo_utils.c @@ -5,8 +5,10 @@ void free_naive(void* app_ctx) { struct algo_ctx* ctx = (struct algo_ctx*) app_ctx; ctx->ref_count--; if (ctx->ref_count > 0) return; + if (ctx->free_misc) ctx->free_misc(ctx->misc); g_queue_free(ctx->free_buffer); g_queue_free(ctx->read_waiting); + g_hash_table_destroy (ctx->application_waiting); g_hash_table_destroy (ctx->used_buffer); g_hash_table_destroy (ctx->write_waiting); free(ctx); diff --git a/src/donar_init.c b/src/donar_init.c index 19cefc3..1a69ddb 100644 --- a/src/donar_init.c +++ b/src/donar_init.c @@ -3,7 +3,7 @@ void free_udp_t(void* v) { struct udp_target* udp_t = v; udp_t->ref_count--; - if (udp_t <= 0) { + if (udp_t->ref_count <= 0) { free(udp_t); } } diff --git a/src/proxy.c b/src/proxy.c index 43450c0..b392dee 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -187,7 +187,7 @@ void algo_main_init(struct evt_core_ctx* evt, struct algo_params* ap) { .name = "tcp-listen", .flags = EPOLLIN, .app_ctx = ctx, - .free_app_ctx = free_nothing, + .free_app_ctx = free_naive, .cb = main_on_tcp_co, .err_cb = NULL };