Module Name:    src
Committed By:   pgoyette
Date:           Tue Aug 29 10:19:54 UTC 2017

Modified Files:
        src/sys/kern: kern_veriexec.c

Log Message:
Release any allocated resources if we take the error paths.

As posted on tech-kern and discussed on IRC.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/kern/kern_veriexec.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/kern/kern_veriexec.c
diff -u src/sys/kern/kern_veriexec.c:1.12 src/sys/kern/kern_veriexec.c:1.13
--- src/sys/kern/kern_veriexec.c:1.12	Wed Apr 12 10:30:02 2017
+++ src/sys/kern/kern_veriexec.c	Tue Aug 29 10:19:54 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_veriexec.c,v 1.12 2017/04/12 10:30:02 hannken Exp $	*/
+/*	$NetBSD: kern_veriexec.c,v 1.13 2017/08/29 10:19:54 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2005, 2006 Elad Efrat <e...@netbsd.org>
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_veriexec.c,v 1.12 2017/04/12 10:30:02 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_veriexec.c,v 1.13 2017/08/29 10:19:54 pgoyette Exp $");
 
 #include "opt_veriexec.h"
 
@@ -1079,7 +1079,7 @@ veriexec_file_add(struct lwp *l, prop_di
 		log(LOG_ERR, "Veriexec: Invalid or unknown fingerprint type "
 		    "`%s' for file `%s'.\n", fp_type, file);
 		error = EOPNOTSUPP;
-		goto out;
+		goto free_out;
 	}
 
 	if (prop_data_size(prop_dictionary_get(dict, "fp")) !=
@@ -1087,7 +1087,7 @@ veriexec_file_add(struct lwp *l, prop_di
 		log(LOG_ERR, "Veriexec: Bad fingerprint length for `%s'.\n",
 		    file);
 		error = EINVAL;
-		goto out;
+		goto free_out;
 	}
 
 	vfe->fp = kmem_alloc(vfe->ops->hash_len, KM_SLEEP);
@@ -1156,8 +1156,16 @@ veriexec_file_add(struct lwp *l, prop_di
 	veriexec_bypass = 0;
 
   unlock_out:
+	if (error)
+		kmem_free(vfe->fp, vfe->ops->hash_len);
 	rw_exit(&veriexec_op_lock);
 
+  free_out:
+	if (error) {
+		rw_destroy(&vfe->lock);
+		kmem_free(vfe, sizeof(*vfe));
+	}
+
   out:
 	vrele(vp);
 	if (error)

Reply via email to