shithub: sl

Download patch

ref: dc5b6960e03cf5ab558fdd5f19f782da1e734f60
parent: 00b0398b4fb4da73a959649fc3fb8ba81f13a2ae
author: spew <spew@cbza.org>
date: Mon Mar 17 18:17:27 EDT 2025

lsd: free_gc_handles on errors

--- a/src/plan9/lsd.c
+++ b/src/plan9/lsd.c
@@ -365,14 +365,15 @@
 		type_error("num", args[0]);
 
 	addr = tosize(args[0]);
-	r = sl_nil;
-	sl_gc_handle(&r);
 	if(machdata->das(coremap, addr, 'i', buf, sizeof(buf)) < 0)
 		lerrorf(sl_errio, "could not disassemble at %ud", addr);
-	r = mk_cons(str_from_cstr(buf), r);
 	size = machdata->instsize(coremap, addr);
 	if(size < 0)
 		lerrorf(sl_errio, "could not get instruction size at %ud", addr);
+
+	r = sl_nil;
+	sl_gc_handle(&r);
+	r = mk_cons(str_from_cstr(buf), r);
 	r = mk_cons(size_wrap(size), r);
 	sl_free_gc_handles(1);
 	return r;
@@ -393,8 +394,10 @@
 	res = tosize(args[2]);
 	tracelist = sl_nil;
 	sl_gc_handle(&tracelist);
-	if(machdata->ctrace(coremap, pc, sp, res, trlist) <= 0)
+	if(machdata->ctrace(coremap, pc, sp, res, trlist) <= 0){
+		sl_free_gc_handles(1);
 		lerrorf(sl_errio, "no stack frame: %r");
+	}
 	sl_free_gc_handles(1);
 	return tracelist;
 }