From 2ef977c03feb2eed74ecf3fda0e792dc3d6a46a5 Mon Sep 17 00:00:00 2001 From: florian Date: Fri, 20 Jul 2018 20:34:18 +0000 Subject: [PATCH] Fix mem leaks on config reload: - always free struct ra_iface_conf with free_ra_iface_conf() - free_ra_iface_conf() needs to free the recently added nameserver and search list --- usr.sbin/rad/parse.y | 4 ++-- usr.sbin/rad/rad.c | 21 +++++++++++++++++---- usr.sbin/rad/rad.h | 6 +++--- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/usr.sbin/rad/parse.y b/usr.sbin/rad/parse.y index e0a4e1386a2..8ffa90569de 100644 --- a/usr.sbin/rad/parse.y +++ b/usr.sbin/rad/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.6 2018/07/20 17:55:09 bket Exp $ */ +/* $OpenBSD: parse.y,v 1.7 2018/07/20 20:34:18 florian Exp $ */ /* * Copyright (c) 2018 Florian Obser @@ -981,7 +981,7 @@ clear_config(struct rad_conf *xconf) while((iface = SIMPLEQ_FIRST(&xconf->ra_iface_list)) != NULL) { SIMPLEQ_REMOVE_HEAD(&xconf->ra_iface_list, entry); - free(iface); + free_ra_iface_conf(iface); } free(xconf); diff --git a/usr.sbin/rad/rad.c b/usr.sbin/rad/rad.c index 7885066a3ea..5343f9afda4 100644 --- a/usr.sbin/rad/rad.c +++ b/usr.sbin/rad/rad.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rad.c,v 1.10 2018/07/20 17:55:09 bket Exp $ */ +/* $OpenBSD: rad.c,v 1.11 2018/07/20 20:34:18 florian Exp $ */ /* * Copyright (c) 2018 Florian Obser @@ -67,7 +67,6 @@ static int main_imsg_send_config(struct rad_conf *); int main_reload(void); int main_sendboth(enum imsg_type, void *, uint16_t); -void free_ra_iface_conf(struct ra_iface_conf *); void in6_prefixlen2mask(struct in6_addr *, int len); struct rad_conf *main_conf; @@ -661,18 +660,32 @@ void free_ra_iface_conf(struct ra_iface_conf *ra_iface_conf) { struct ra_prefix_conf *prefix; + struct ra_rdnss_conf *ra_rdnss; + struct ra_dnssl_conf *ra_dnssl; if (!ra_iface_conf) return; free(ra_iface_conf->autoprefix); - while ((prefix = SIMPLEQ_FIRST(&ra_iface_conf->ra_prefix_list)) - != NULL) { + while ((prefix = SIMPLEQ_FIRST(&ra_iface_conf->ra_prefix_list)) != + NULL) { SIMPLEQ_REMOVE_HEAD(&ra_iface_conf->ra_prefix_list, entry); free(prefix); } + while ((ra_rdnss = SIMPLEQ_FIRST(&ra_iface_conf->ra_rdnss_list)) != + NULL) { + SIMPLEQ_REMOVE_HEAD(&ra_iface_conf->ra_rdnss_list, entry); + free(ra_rdnss); + } + + while ((ra_dnssl = SIMPLEQ_FIRST(&ra_iface_conf->ra_dnssl_list)) != + NULL) { + SIMPLEQ_REMOVE_HEAD(&ra_iface_conf->ra_dnssl_list, entry); + free(ra_dnssl); + } + free(ra_iface_conf); } diff --git a/usr.sbin/rad/rad.h b/usr.sbin/rad/rad.h index a8b8ba116c4..b7b68d3a81f 100644 --- a/usr.sbin/rad/rad.h +++ b/usr.sbin/rad/rad.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rad.h,v 1.12 2018/07/20 17:55:09 bket Exp $ */ +/* $OpenBSD: rad.h,v 1.13 2018/07/20 20:34:18 florian Exp $ */ /* * Copyright (c) 2018 Florian Obser @@ -154,8 +154,8 @@ int imsg_compose_event(struct imsgev *, uint16_t, uint32_t, pid_t, struct rad_conf *config_new_empty(void); void config_clear(struct rad_conf *); - -void mask_prefix(struct in6_addr*, int len); +void free_ra_iface_conf(struct ra_iface_conf *); +void mask_prefix(struct in6_addr*, int len); const char *sin6_to_str(struct sockaddr_in6 *); const char *in6_to_str(struct in6_addr *); -- 2.20.1