[RFA,05/10] Avoid manual resource management in py-framefilter.c

Message ID 20170425194113.17862-6-tom@tromey.com
State New, archived
Headers

Commit Message

Tom Tromey April 25, 2017, 7:41 p.m. UTC
  This patch removes the last bit of manual resource management from
py-framefilter.c.  This will be useful in the next patch.

ChangeLog
2017-04-25  Tom Tromey  <tom@tromey.com>

	* python/py-framefilter.c (enumerate_args): Use
	gdb::unique_xmalloc_ptr.
---
 gdb/ChangeLog               |  5 +++++
 gdb/python/py-framefilter.c | 20 +++++---------------
 2 files changed, 10 insertions(+), 15 deletions(-)
  

Comments

Phil Muldoon April 28, 2017, 2:53 p.m. UTC | #1
On 25/04/17 20:41, Tom Tromey wrote:
> This patch removes the last bit of manual resource management from
> py-framefilter.c.  This will be useful in the next patch.
> 
> ChangeLog
> 2017-04-25  Tom Tromey  <tom@tromey.com>
> 
> 	* python/py-framefilter.c (enumerate_args): Use
> 	gdb::unique_xmalloc_ptr.

LGTM (and much cleaner). Thanks for doing this and the original automated resource management and reference counting from previous patches.

Cheers

Phil
  
Pedro Alves June 27, 2017, 4:43 p.m. UTC | #2
On 04/25/2017 08:41 PM, Tom Tromey wrote:
> This patch removes the last bit of manual resource management from
> py-framefilter.c.  This will be useful in the next patch.
> 
> ChangeLog
> 2017-04-25  Tom Tromey  <tom@tromey.com>
> 
> 	* python/py-framefilter.c (enumerate_args): Use
> 	gdb::unique_xmalloc_ptr.

OK.

Thanks,
Pedro Alves
  

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 176332a..6b0c584 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@ 
 2017-04-25  Tom Tromey  <tom@tromey.com>
 
+	* python/py-framefilter.c (enumerate_args): Use
+	gdb::unique_xmalloc_ptr.
+
+2017-04-25  Tom Tromey  <tom@tromey.com>
+
 	* python/py-framefilter.c (py_print_frame): Return
 	EXT_LANG_BT_OK.
 	(gdbpy_apply_frame_filter): Update comment.
diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
index 2bbbfbe..2ae2158 100644
--- a/gdb/python/py-framefilter.c
+++ b/gdb/python/py-framefilter.c
@@ -560,6 +560,9 @@  enumerate_args (PyObject *iter,
 	    }
 	  END_CATCH
 
+	  gdb::unique_xmalloc_ptr<char> arg_holder (arg.error);
+	  gdb::unique_xmalloc_ptr<char> entry_holder (entryarg.error);
+
 	  /* The object has not provided a value, so this is a frame
 	     argument to be read by GDB.  In this case we have to
 	     account for entry-values.  */
@@ -571,11 +574,7 @@  enumerate_args (PyObject *iter,
 				       args_type,
 				       print_args_field,
 				       NULL) == EXT_LANG_BT_ERROR)
-		{
-		  xfree (arg.error);
-		  xfree (entryarg.error);
-		  return EXT_LANG_BT_ERROR;
-		}
+		return EXT_LANG_BT_ERROR;
 	    }
 
 	  if (entryarg.entry_kind != print_entry_values_no)
@@ -589,8 +588,6 @@  enumerate_args (PyObject *iter,
 		    }
 		  CATCH (except, RETURN_MASK_ALL)
 		    {
-		      xfree (arg.error);
-		      xfree (entryarg.error);
 		      gdbpy_convert_exception (except);
 		      return EXT_LANG_BT_ERROR;
 		    }
@@ -600,15 +597,8 @@  enumerate_args (PyObject *iter,
 	      if (py_print_single_arg (out, NULL, &entryarg, NULL, &opts,
 				       args_type, print_args_field, NULL)
 		  == EXT_LANG_BT_ERROR)
-		{
-		  xfree (arg.error);
-		  xfree (entryarg.error);
-		  return EXT_LANG_BT_ERROR;
-		}
+		return EXT_LANG_BT_ERROR;
 	    }
-
-	  xfree (arg.error);
-	  xfree (entryarg.error);
 	}
       else
 	{