Euphoria Ticket #963: Integer with delete_routine used as case value

Reduced test case from this forum post reported by jessedavis

procedure delete_proc(object x) 
  puts(1, "deleting ") 
  ? x 
end procedure 
 
constant op = delete_routine(1, routine_id("delete_proc")) 
 
switch op do 
  case op then 
    puts(1, "in first case...\n") 
end switch 

deleting 1 
 
/home/pete/Downloads/euphoria-4.1.0-Linux-x64/switchdelete.ex:8 
A machine-level exception occurred during execution of this statement (signal 11)  
 
--> See ex.err  

Details

Type: Bug Report Severity: Major Category: Interpreter
Assigned To: ghaberek Status: Accepted Reported Release: 4.1.0
Fixed in SVN #: View VCS: none Milestone: 4.2.0

1. Comment by irv Nov 12, 2022

six years, no progress: 4.2 currently gives the same results.

2. Comment by ghaberek Nov 14, 2022

Looks like there are a few things going on here:

  • L1614 we are de-referencing the object from values[i] without ever adding a reference to it, so the delete routine for the object gets called immediately
  • L1643 we are storing the original object from values[i] but we may have stripped it down to an integer up at L1612, so we should use that instead
  • L1706 we are de-referencing the original values from the call stack instead of our temporary new_values sequence, which wouldn't get freed otherwise

I'd like some feedback and sanity-checking if anyone is so inclined. Here's a patch for the changes:

diff --git a/source/be_execute.c b/source/be_execute.c 
index 69f4a1f7..c0c1590d 100644 
--- a/source/be_execute.c 
+++ b/source/be_execute.c 
@@ -1614 +1613,0 @@ void analyze_switch() 
-                                       DeRefDS(top); 
@@ -1639,5 +1637,0 @@ void analyze_switch() 
-                       new_values->base[i] = top; 
-               } 
-               else{ 
- 
-                       new_values->base[i] = fe.st[sym].obj; 
@@ -1644,0 +1639 @@ void analyze_switch() 
+               new_values->base[i] = top; 
@@ -1706 +1700,0 @@ void analyze_switch() 
-       DeRefDS( MAKE_SEQ( values ) ); 
@@ -1731,0 +1726 @@ void analyze_switch() 
+       DeRefDS( MAKE_SEQ( new_values ) ); 

-Greg

3. Comment by jimcbrown Jan 25, 2023

Patch looks good to me.

Search



Quick Links

User menu

Not signed in.

Misc Menu