summaryrefslogtreecommitdiffstats
path: root/sys/net/route.c
diff options
context:
space:
mode:
authormpi <mpi@openbsd.org>2016-05-31 07:29:34 +0000
committermpi <mpi@openbsd.org>2016-05-31 07:29:34 +0000
commitc72f756c39ee67ae90f4aa5a30a3760179c4de6b (patch)
treeb7207ea93f9bdfd24c0b60dc74cbf5f38ce5b665 /sys/net/route.c
parentreplace m_copym2 with m_dup_pkt. (diff)
downloadwireguard-openbsd-c72f756c39ee67ae90f4aa5a30a3760179c4de6b.tar.xz
wireguard-openbsd-c72f756c39ee67ae90f4aa5a30a3760179c4de6b.zip
Plug a route entry leak triggered under memory pressure.
Help to track the leak from Hrvoje Popovski, ok bluhm@
Diffstat (limited to 'sys/net/route.c')
-rw-r--r--sys/net/route.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/sys/net/route.c b/sys/net/route.c
index 33f9a42a43b..28a00a8315c 100644
--- a/sys/net/route.c
+++ b/sys/net/route.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: route.c,v 1.300 2016/05/02 22:15:49 jmatthew Exp $ */
+/* $OpenBSD: route.c,v 1.301 2016/05/31 07:29:34 mpi Exp $ */
/* $NetBSD: route.c,v 1.14 1996/02/13 22:00:46 christos Exp $ */
/*
@@ -1091,6 +1091,10 @@ rtrequest(int req, struct rt_addrinfo *info, u_int8_t prio,
* it to (re)order routes.
*/
if ((error = rt_setgate(rt, info->rti_info[RTAX_GATEWAY]))) {
+ ifafree(ifa);
+ rtfree(rt->rt_parent);
+ rtfree(rt->rt_gwroute);
+ free(rt->rt_gateway, M_RTABLE, 0);
free(ndst, M_RTABLE, dlen);
pool_put(&rtentry_pool, rt);
return (error);
@@ -1118,12 +1122,9 @@ rtrequest(int req, struct rt_addrinfo *info, u_int8_t prio,
}
if (error != 0) {
ifafree(ifa);
- if ((rt->rt_flags & RTF_CLONED) != 0 && rt->rt_parent)
- rtfree(rt->rt_parent);
- if (rt->rt_gwroute)
- rtfree(rt->rt_gwroute);
- if (rt->rt_gateway)
- free(rt->rt_gateway, M_RTABLE, 0);
+ rtfree(rt->rt_parent);
+ rtfree(rt->rt_gwroute);
+ free(rt->rt_gateway, M_RTABLE, 0);
free(ndst, M_RTABLE, dlen);
pool_put(&rtentry_pool, rt);
return (EEXIST);
@@ -1163,10 +1164,8 @@ rt_setgate(struct rtentry *rt, struct sockaddr *gate)
}
memmove(rt->rt_gateway, gate, glen);
- if (rt->rt_gwroute != NULL) {
- rtfree(rt->rt_gwroute);
- rt->rt_gwroute = NULL;
- }
+ rtfree(rt->rt_gwroute);
+ rt->rt_gwroute = NULL;
return (0);
}