Remove a cleanup from scm-frame.c
authorTom Tromey <tom@tromey.com>
Sat, 21 Apr 2018 22:38:33 +0000 (16:38 -0600)
committerTom Tromey <tom@tromey.com>
Mon, 23 Apr 2018 23:50:19 +0000 (17:50 -0600)
This removes a cleanup from scm-frame.c, replacing it with
unique_xmalloc_ptr and a new scope.  I believe this also fixes a
latent bug involving calling do_cleanups twice for a single cleanup.

Regression tested using the gdb.guile test suite on x86-64 Fedora 26.

ChangeLog
2018-04-23  Tom Tromey  <tom@tromey.com>

* guile/scm-frame.c (gdbscm_frame_read_var): Use
gdb::unique_xmalloc_ptr.

gdb/ChangeLog
gdb/guile/scm-frame.c

index d18081e04cd34026cb00b633603fabed1a16654a..bec33b60e446ccaccc75558b12f1c5a26862e8a1 100644 (file)
@@ -1,3 +1,8 @@
+2018-04-23  Tom Tromey  <tom@tromey.com>
+
+       * guile/scm-frame.c (gdbscm_frame_read_var): Use
+       gdb::unique_xmalloc_ptr.
+
 2018-04-23  Tom Tromey  <tom@tromey.com>
 
        * configure: Rebuild.
index 4f4766aceb4f23a29e0f839f01c9c12433a8a335..7b539677ffdf4cc0e82c65d36a9a2d191a9b0f0a 100644 (file)
@@ -877,7 +877,6 @@ gdbscm_frame_read_var (SCM self, SCM symbol_scm, SCM rest)
     }
   else if (scm_is_string (symbol_scm))
     {
-      char *var_name;
       const struct block *block = NULL;
       struct cleanup *cleanup;
       struct gdb_exception except = exception_none;
@@ -893,38 +892,35 @@ gdbscm_frame_read_var (SCM self, SCM symbol_scm, SCM rest)
            gdbscm_throw (except_scm);
        }
 
-      var_name = gdbscm_scm_to_c_string (symbol_scm);
-      cleanup = make_cleanup (xfree, var_name);
-      /* N.B. Between here and the call to do_cleanups, don't do anything
-        to cause a Scheme exception without performing the cleanup.  */
+      {
+       gdb::unique_xmalloc_ptr<char> var_name
+         (gdbscm_scm_to_c_string (symbol_scm));
+       /* N.B. Between here and the end of the scope, don't do anything
+          to cause a Scheme exception.  */
+
+       TRY
+         {
+           struct block_symbol lookup_sym;
+
+           if (block == NULL)
+             block = get_frame_block (frame, NULL);
+           lookup_sym = lookup_symbol (var_name.get (), block, VAR_DOMAIN,
+                                       NULL);
+           var = lookup_sym.symbol;
+           block = lookup_sym.block;
+         }
+       CATCH (ex, RETURN_MASK_ALL)
+         {
+           except = ex;
+         }
+       END_CATCH
+      }
 
-      TRY
-       {
-         struct block_symbol lookup_sym;
-
-         if (block == NULL)
-           block = get_frame_block (frame, NULL);
-         lookup_sym = lookup_symbol (var_name, block, VAR_DOMAIN, NULL);
-         var = lookup_sym.symbol;
-         block = lookup_sym.block;
-       }
-      CATCH (ex, RETURN_MASK_ALL)
-       {
-         except = ex;
-       }
-      END_CATCH
-
-      do_cleanups (cleanup);
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
 
       if (var == NULL)
-       {
-         do_cleanups (cleanup);
-         gdbscm_out_of_range_error (FUNC_NAME, 0, symbol_scm,
-                                    _("variable not found"));
-       }
-
-      do_cleanups (cleanup);
+       gdbscm_out_of_range_error (FUNC_NAME, 0, symbol_scm,
+                                  _("variable not found"));
     }
   else
     {