Source-Changes-HG archive

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

[src/trunk]: src/sys/kern Release any allocated resources if we take the erro...



details:   https://anonhg.NetBSD.org/src/rev/0f0e96582ff0
branches:  trunk
changeset: 826350:0f0e96582ff0
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Tue Aug 29 10:19:54 2017 +0000

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

As posted on tech-kern and discussed on IRC.

diffstat:

 sys/kern/kern_veriexec.c |  16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

diffs (53 lines):

diff -r ec633ae16f92 -r 0f0e96582ff0 sys/kern/kern_veriexec.c
--- a/sys/kern/kern_veriexec.c  Tue Aug 29 10:10:54 2017 +0000
+++ b/sys/kern/kern_veriexec.c  Tue Aug 29 10:19:54 2017 +0000
@@ -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 <elad%NetBSD.org@localhost>
@@ -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 @@
                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 @@
                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_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)



Home | Main Index | Thread Index | Old Index