From 1b06e8c0547de9e43f59bb11179216d25655305f Mon Sep 17 00:00:00 2001
From: Ian Moffett <ian@osmora.org>
Date: Sat, 27 Apr 2024 00:54:37 -0400
Subject: kernel: kern_exec: Fixup cleanup in execv()

Signed-off-by: Ian Moffett <ian@osmora.org>
---
 sys/kern/kern_exec.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

(limited to 'sys/kern')

diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c
index 1c91025..bcd7a2e 100644
--- a/sys/kern/kern_exec.c
+++ b/sys/kern/kern_exec.c
@@ -130,7 +130,7 @@ exec_set_stack(struct proc *td, struct exec_args args)
 static int
 execv(char *pathname, char **argv, uintptr_t *sp_res)
 {
-    char *bin;
+    char *bin = NULL;
     struct filedesc *filedes;
     struct vm_range *exec_range;
     struct exec_args args;
@@ -204,10 +204,11 @@ execv(char *pathname, char **argv, uintptr_t *sp_res)
     *sp_res = exec_set_stack(td, args);
     set_frame_ip(td->tf, args.auxv.at_entry);
 done:
-    /* We are done, free argp and release the thread */
+    /* We are done, cleanup and release the thread */
+    if (bin != NULL) dynfree(bin);
     fd_close_fdnum(td, fd);
-    spinlock_release(&td->lock);
     dynfree(args.argp);
+    spinlock_release(&td->lock);
     return ret;
 }
 
-- 
cgit v1.2.3