Module Name:    src
Committed By:   riastradh
Date:           Mon Aug 31 20:34:43 UTC 2020

Modified Files:
        src/sys/net: if_wg.c

Log Message:
wg: Avoid memory leak if socreate fails.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/sys/net/if_wg.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/if_wg.c
diff -u src/sys/net/if_wg.c:1.50 src/sys/net/if_wg.c:1.51
--- src/sys/net/if_wg.c:1.50	Mon Aug 31 20:34:18 2020
+++ src/sys/net/if_wg.c	Mon Aug 31 20:34:43 2020
@@ -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.ry...@gmail.com>
@@ -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 @@ wg_worker_init(struct wg_softc *wg)
 	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 @@ error:
 	cv_destroy(&wgw->wgw_cv);
 	mutex_destroy(&wgw->wgw_lock);
 
+	kmem_free(wgw, sizeof(*wgw));
+
 	return error;
 }
 

Reply via email to