Bug 201350

Summary: loader nextboot will leave trash in stack
Product: Base System Reporter: Toomas Soome <tsoome>
Component: kernAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Many People CC: dteske, gonzo, tsoome
Priority: --- Keywords: patch
Version: CURRENT   
Hardware: Any   
OS: Any   

Description Toomas Soome 2015-07-05 00:19:19 UTC
the include_nextboot_file word is using catch to intercept errors from file io, and leaves trash in stack; 

it happens because before ['] peek_file catch the get_nextboot_conf_file leaves stack as ( addr len ) and catch will restore stack pointer to the same state (but not values!). to clean up, following update will do:

: include_nextboot_file
-  get_nextboot_conf_file
-  ['] peek_file catch
+  get_nextboot_conf_file               ( addr len )
+  ['] peek_file catch                  ( addr len code )
+  dup EOPEN = if
+    drop       ( drop exception code )
+    2drop      ( drop file name restored by catch )
+  else
+    throw
+  then


the throw/catch mechanism is described very nicely by www.complang.tuwien.ac.at/anton/euroforth/ef98/milendorf98.pdf

btw, also related to nextboot, yes that strdup is leak and not needed at all;)
: get_nextboot_conf_file ( -- addr len )
-  nextboot_conf_file strget strdup     \ XXX is the strdup a leak ?
+  nextboot_conf_file strget
 ;
Comment 1 Oleksandr Tymoshenko freebsd_committer freebsd_triage 2019-01-17 00:18:28 UTC
Hi Toomas,

I am going over old PRs. Is this one still valid? If so, could you take care of it since you have commit bit now :)
Comment 2 Toomas Soome freebsd_committer freebsd_triage 2019-01-17 12:21:17 UTC
(In reply to Oleksandr Tymoshenko from comment #1)
Yes it appears to be fixed.