Source-Changes-HG archive

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

[src/trunk]: src/sys/kern keep track of the original array length so we can p...



details:   https://anonhg.NetBSD.org/src/rev/9375daedb0d6
branches:  trunk
changeset: 777505:9375daedb0d6
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Feb 21 04:13:22 2012 +0000

description:
keep track of the original array length so we can pass it to kmem_free, from
enami

diffstat:

 sys/kern/kern_exec.c |  25 +++++++++++--------------
 1 files changed, 11 insertions(+), 14 deletions(-)

diffs (91 lines):

diff -r 9f07e1929c43 -r 9375daedb0d6 sys/kern/kern_exec.c
--- a/sys/kern/kern_exec.c      Tue Feb 21 03:44:54 2012 +0000
+++ b/sys/kern/kern_exec.c      Tue Feb 21 04:13:22 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_exec.c,v 1.343 2012/02/21 03:44:54 christos Exp $ */
+/*     $NetBSD: kern_exec.c,v 1.344 2012/02/21 04:13:22 christos Exp $ */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.343 2012/02/21 03:44:54 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.344 2012/02/21 04:13:22 christos Exp $");
 
 #include "opt_exec.h"
 #include "opt_ktrace.h"
@@ -1917,10 +1917,10 @@
 }
 
 static void
-posix_spawn_fa_free(struct posix_spawn_file_actions *fa)
+posix_spawn_fa_free(struct posix_spawn_file_actions *fa, size_t len)
 {
 
-       for (size_t i = 0; i < fa->len; i++) {
+       for (size_t i = 0; i < len; i++) {
                struct posix_spawn_file_actions_entry *fae = &fa->fae[i];
                if (fae->fae_action != FAE_OPEN)
                        continue;
@@ -1939,6 +1939,7 @@
        struct posix_spawn_file_actions_entry *fae;
        char *pbuf = NULL;
        int error;
+       size_t i = 0;
 
        fa = kmem_alloc(sizeof(*fa), KM_SLEEP);
        error = copyin(ufa, fa, sizeof(*fa));
@@ -1955,21 +1956,17 @@
        fae = fa->fae;
        fa->fae = kmem_alloc(fal, KM_SLEEP);
        error = copyin(fae, fa->fae, fal);
-       if (error) {
-               fa->len = 0;
+       if (error)
                goto out;
-       }
 
        pbuf = PNBUF_GET();
-       for (size_t i = 0; i < fa->len; i++) {
+       for (; i < fa->len; i++) {
                fae = &fa->fae[i];
                if (fae->fae_action != FAE_OPEN)
                        continue;
                error = copyinstr(fae->fae_path, pbuf, MAXPATHLEN, &fal);
-               if (error) {
-                       fa->len = i;
+               if (error)
                        goto out;
-               }
                fae->fae_path = kmem_alloc(fal, KM_SLEEP);
                memcpy(fae->fae_path, pbuf, fal);
        }
@@ -1979,7 +1976,7 @@
 out:
        if (pbuf)
                PNBUF_PUT(pbuf);
-       posix_spawn_fa_free(fa);
+       posix_spawn_fa_free(fa, i);
        return error;
 }
 
@@ -2281,7 +2278,7 @@
        have_exec_lock = false;
 
        if (fa)
-               posix_spawn_fa_free(fa);
+               posix_spawn_fa_free(fa, fa->len);
 
        if (sa) 
                kmem_free(sa, sizeof(*sa));
@@ -2302,7 +2299,7 @@
                rw_exit(&exec_lock);
  
        if (fa)
-               posix_spawn_fa_free(fa);
+               posix_spawn_fa_free(fa, fa->len);
 
        if (sa) 
                kmem_free(sa, sizeof(*sa));



Home | Main Index | Thread Index | Old Index