From: W.C.A. Wijngaards Date: Thu, 24 Oct 2019 07:58:45 +0000 (+0200) Subject: - Fix #99: Memory leak in ub_ctx (event_base will never be freed). X-Git-Tag: release-1.9.6rc1~81 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7dfbcdf276e7a1070978209d2533b3b8cc504f86;p=thirdparty%2Funbound.git - Fix #99: Memory leak in ub_ctx (event_base will never be freed). --- diff --git a/doc/Changelog b/doc/Changelog index 11f59f42f..3a00c686e 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,3 +1,6 @@ +24 October 2019: Wouter + - Fix #99: Memory leak in ub_ctx (event_base will never be freed). + 23 October 2019: George - Add new configure option `--enable-fully-static` to enable full static build if requested; in relation to #91. diff --git a/libunbound/context.h b/libunbound/context.h index c3900154f..78f8731e2 100644 --- a/libunbound/context.h +++ b/libunbound/context.h @@ -119,6 +119,9 @@ struct ub_ctx { /** event base for event oriented interface */ struct ub_event_base* event_base; + /** true if the event_base is a pluggable base that is malloced + * with a user event base inside, if so, clean up the pluggable alloc*/ + int event_base_malloced; /** libworker for event based interface */ struct libworker* event_worker; diff --git a/libunbound/libunbound.c b/libunbound/libunbound.c index 63770cc02..f86f56835 100644 --- a/libunbound/libunbound.c +++ b/libunbound/libunbound.c @@ -226,6 +226,7 @@ ub_ctx_create_event(struct event_base* eb) ub_ctx_delete(ctx); return NULL; } + ctx->event_base_malloced = 1; return ctx; } @@ -336,6 +337,8 @@ ub_ctx_delete(struct ub_ctx* ctx) log_file(NULL); ctx_logfile_overridden = 0; } + if(ctx->event_base_malloced) + free(ctx->event_base); free(ctx); #ifdef USE_WINSOCK WSACleanup();