diff -r 758de955caca libinterp/corefcn/call-stack.h
--- a/libinterp/corefcn/call-stack.h	Tue Feb 07 08:18:54 2023 -0800
+++ b/libinterp/corefcn/call-stack.h	Tue Feb 07 17:53:19 2023 -0500
@@ -88,7 +88,12 @@ public:
 
   std::size_t size () const { return m_cs.size (); }
 
-  std::shared_ptr<stack_frame> get_current_stack_frame () const
+  const std::shared_ptr<stack_frame>& get_current_stack_frame () const
+  {
+    return m_cs[m_curr_frame];
+  }
+
+  std::shared_ptr<stack_frame>& get_current_stack_frame ()
   {
     return m_cs[m_curr_frame];
   }
diff -r 758de955caca libinterp/parse-tree/pt-eval.cc
--- a/libinterp/parse-tree/pt-eval.cc	Tue Feb 07 08:18:54 2023 -0800
+++ b/libinterp/parse-tree/pt-eval.cc	Tue Feb 07 17:53:19 2023 -0500
@@ -1893,7 +1893,7 @@ tree_evaluator::is_defined (const tree_e
 bool
 tree_evaluator::is_variable (const symbol_record& sym) const
 {
-  std::shared_ptr<stack_frame> frame
+  const std::shared_ptr<stack_frame> &frame
     = m_call_stack.get_current_stack_frame ();
 
   return frame->is_variable (sym);
@@ -1902,7 +1902,7 @@ tree_evaluator::is_variable (const symbo
 bool
 tree_evaluator::is_defined (const symbol_record& sym) const
 {
-  std::shared_ptr<stack_frame> frame
+  const std::shared_ptr<stack_frame> &frame
     = m_call_stack.get_current_stack_frame ();
 
   return frame->is_defined (sym);
@@ -1910,7 +1910,7 @@ tree_evaluator::is_defined (const symbol
 
 bool tree_evaluator::is_global (const std::string& name) const
 {
-  std::shared_ptr<stack_frame> frame
+  const std::shared_ptr<stack_frame> &frame
     = m_call_stack.get_current_stack_frame ();
 
   return frame->is_global (name);
@@ -1919,7 +1919,7 @@ bool tree_evaluator::is_global (const st
 octave_value
 tree_evaluator::varval (const symbol_record& sym) const
 {
-  std::shared_ptr<stack_frame> frame
+  const std::shared_ptr<stack_frame> &frame
     = m_call_stack.get_current_stack_frame ();
 
   return frame->varval (sym);
@@ -1928,7 +1928,7 @@ tree_evaluator::varval (const symbol_rec
 octave_value
 tree_evaluator::varval (const std::string& name) const
 {
-  std::shared_ptr<stack_frame> frame
+  const std::shared_ptr<stack_frame> &frame
     = m_call_stack.get_current_stack_frame ();
 
   return frame->varval (name);
@@ -1938,7 +1938,7 @@ void tree_evaluator::install_variable (c
                                        const octave_value& value,
                                        bool global)
 {
-  std::shared_ptr<stack_frame> frame
+  std::shared_ptr<stack_frame> &frame
     = m_call_stack.get_current_stack_frame ();
 
   return frame->install_variable (name, value, global);
@@ -1979,7 +1979,7 @@ tree_evaluator::top_level_assign (const 
 void
 tree_evaluator::assign (const std::string& name, const octave_value& val)
 {
-  std::shared_ptr<stack_frame> frame
+  std::shared_ptr<stack_frame> &frame
     = m_call_stack.get_current_stack_frame ();
 
   frame->assign (name, val);
@@ -2693,7 +2693,7 @@ void tree_evaluator::display_call_stack 
 
 octave_value tree_evaluator::find (const std::string& name)
 {
-  std::shared_ptr<stack_frame> frame
+  std::shared_ptr<stack_frame>& frame
     = m_call_stack.get_current_stack_frame ();
 
   octave_value val = frame->varval (name);
@@ -2717,7 +2717,7 @@ octave_value tree_evaluator::find (const
 
 void tree_evaluator::clear_objects ()
 {
-  std::shared_ptr<stack_frame> frame
+  std::shared_ptr<stack_frame>& frame
     = m_call_stack.get_current_stack_frame ();
 
   frame->clear_objects ();
@@ -2725,7 +2725,7 @@ void tree_evaluator::clear_objects ()
 
 void tree_evaluator::clear_variable (const std::string& name)
 {
-  std::shared_ptr<stack_frame> frame
+  std::shared_ptr<stack_frame>& frame
     = m_call_stack.get_current_stack_frame ();
 
   frame->clear_variable (name);
@@ -2733,7 +2733,7 @@ void tree_evaluator::clear_variable (con
 
 void tree_evaluator::clear_variable_pattern (const std::string& pattern)
 {
-  std::shared_ptr<stack_frame> frame
+  std::shared_ptr<stack_frame>& frame
     = m_call_stack.get_current_stack_frame ();
 
   frame->clear_variable_pattern (pattern);
@@ -2741,7 +2741,7 @@ void tree_evaluator::clear_variable_patt
 
 void tree_evaluator::clear_variable_regexp (const std::string& pattern)
 {
-  std::shared_ptr<stack_frame> frame
+  std::shared_ptr<stack_frame>& frame
     = m_call_stack.get_current_stack_frame ();
 
   frame->clear_variable_regexp (pattern);
@@ -2749,7 +2749,7 @@ void tree_evaluator::clear_variable_rege
 
 void tree_evaluator::clear_variables ()
 {
-  std::shared_ptr<stack_frame> frame
+  std::shared_ptr<stack_frame>& frame
     = m_call_stack.get_current_stack_frame ();
 
   frame->clear_variables ();
