This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA 4/6] Remove some more cleanups from ada-lang.c


This removes a few more cleanups from ada-lang.c by using
unique_xmalloc_ptr in a couple of spots.

ChangeLog
2017-11-29  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (ada_exception_message_1): Return
	unique_xmalloc_ptr.
	(ada_exception_message_1): Update.
	(ada_exception_message): Return unique_xmalloc_ptr.
	(print_it_exception): Update.
---
 gdb/ChangeLog  |  8 ++++++++
 gdb/ada-lang.c | 31 +++++++++----------------------
 2 files changed, 17 insertions(+), 22 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 0248663ba8..8d0ac60575 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -12088,8 +12088,6 @@ ada_exception_name_addr_1 (enum ada_exception_catchpoint_kind ex,
    return the message which was associated to the exception, if
    available.  Return NULL if the message could not be retrieved.
 
-   The caller must xfree the string after use.
-
    Note: The exception message can be associated to an exception
    either through the use of the Raise_Exception function, or
    more simply (Ada 2005 and later), via:
@@ -12098,13 +12096,11 @@ ada_exception_name_addr_1 (enum ada_exception_catchpoint_kind ex,
 
    */
 
-static char *
+static gdb::unique_xmalloc_ptr<char>
 ada_exception_message_1 (void)
 {
   struct value *e_msg_val;
-  char *e_msg = NULL;
   int e_msg_len;
-  struct cleanup *cleanups;
 
   /* For runtimes that support this feature, the exception message
      is passed as an unbounded string argument called "message".  */
@@ -12121,34 +12117,30 @@ ada_exception_message_1 (void)
   if (e_msg_len <= 0)
     return NULL;
 
-  e_msg = (char *) xmalloc (e_msg_len + 1);
-  cleanups = make_cleanup (xfree, e_msg);
+  gdb::unique_xmalloc_ptr<char> result ((char *) xmalloc (e_msg_len + 1));
+  char *e_msg = result.get ();
   read_memory_string (value_address (e_msg_val), e_msg, e_msg_len + 1);
   e_msg[e_msg_len] = '\0';
 
-  discard_cleanups (cleanups);
-  return e_msg;
+  return result;
 }
 
 /* Same as ada_exception_message_1, except that all exceptions are
    contained here (returning NULL instead).  */
 
-static char *
+static gdb::unique_xmalloc_ptr<char>
 ada_exception_message (void)
 {
-  char *e_msg = NULL;  /* Avoid a spurious uninitialized warning.  */
-
   TRY
     {
-      e_msg = ada_exception_message_1 ();
+      return ada_exception_message_1 ();
     }
   CATCH (e, RETURN_MASK_ERROR)
     {
-      e_msg = NULL;
     }
   END_CATCH
 
-  return e_msg;
+  return nullptr;
 }
 
 /* Same as ada_exception_name_addr_1, except that it intercepts and contains
@@ -12383,7 +12375,6 @@ print_it_exception (enum ada_exception_catchpoint_kind ex, bpstat bs)
 {
   struct ui_out *uiout = current_uiout;
   struct breakpoint *b = bs->breakpoint_at;
-  char *exception_message;
 
   annotate_catchpoint (b->number);
 
@@ -12450,16 +12441,12 @@ print_it_exception (enum ada_exception_catchpoint_kind ex, bpstat bs)
 	break;
     }
 
-  exception_message = ada_exception_message ();
+  gdb::unique_xmalloc_ptr<char> exception_message = ada_exception_message ();
   if (exception_message != NULL)
     {
-      struct cleanup *cleanups = make_cleanup (xfree, exception_message);
-
       uiout->text (" (");
-      uiout->field_string ("exception-message", exception_message);
+      uiout->field_string ("exception-message", exception_message.get ());
       uiout->text (")");
-
-      do_cleanups (cleanups);
     }
 
   uiout->text (" at ");
-- 
2.13.6


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]