Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/net wg: Avoid memory leak if socreate fails.



details:   https://anonhg.NetBSD.org/src/rev/cc21e69932fd
branches:  trunk
changeset: 943361:cc21e69932fd
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Mon Aug 31 20:34:43 2020 +0000

description:
wg: Avoid memory leak if socreate fails.

diffstat:

 sys/net/if_wg.c |  8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diffs (36 lines):

diff -r a5c7767649bb -r cc21e69932fd sys/net/if_wg.c
--- a/sys/net/if_wg.c   Mon Aug 31 20:34:18 2020 +0000
+++ b/sys/net/if_wg.c   Mon Aug 31 20:34:43 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_wg.c,v 1.50 2020/08/31 20:34:18 riastradh Exp $     */
+/*     $NetBSD: if_wg.c,v 1.51 2020/08/31 20:34:43 riastradh Exp $     */
 
 /*
  * Copyright (C) Ryota Ozaki <ozaki.ryota%gmail.com@localhost>
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.50 2020/08/31 20:34:18 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.51 2020/08/31 20:34:43 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -3177,7 +3177,7 @@
        const char *ifname = wg->wg_if.if_xname;
        struct socket *so;
 
-       wgw = kmem_zalloc(sizeof(struct wg_worker), KM_SLEEP);
+       wgw = kmem_zalloc(sizeof(*wgw), KM_SLEEP);
 
        mutex_init(&wgw->wgw_lock, MUTEX_DEFAULT, IPL_SOFTNET);
        cv_init(&wgw->wgw_cv, ifname);
@@ -3214,6 +3214,8 @@
        cv_destroy(&wgw->wgw_cv);
        mutex_destroy(&wgw->wgw_lock);
 
+       kmem_free(wgw, sizeof(*wgw));
+
        return error;
 }
 



Home | Main Index | Thread Index | Old Index