[1/8] Remove a use of xfree

Message ID 20230709-trace-cleanups-v1-1-c410e1072fab@tromey.com
State New
Headers
Series Minor C++-ification and cleanup in trace targets |

Commit Message

Tom Tromey July 9, 2023, 5:01 p.m. UTC
  This removes a use of xfree from tracefile-tfile.c, replacing it with
a unique_xmalloc_ptr.
---
 gdb/tracefile-tfile.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
  

Patch

diff --git a/gdb/tracefile-tfile.c b/gdb/tracefile-tfile.c
index 9203bcc2e4b..ff451c79e88 100644
--- a/gdb/tracefile-tfile.c
+++ b/gdb/tracefile-tfile.c
@@ -225,22 +225,19 @@  static void
 tfile_write_uploaded_tsv (struct trace_file_writer *self,
 			  struct uploaded_tsv *utsv)
 {
-  char *buf = NULL;
+  gdb::unique_xmalloc_ptr<char> buf;
   struct tfile_trace_file_writer *writer
     = (struct tfile_trace_file_writer *) self;
 
   if (utsv->name)
     {
-      buf = (char *) xmalloc (strlen (utsv->name) * 2 + 1);
-      bin2hex ((gdb_byte *) (utsv->name), buf, strlen (utsv->name));
+      buf.reset ((char *) xmalloc (strlen (utsv->name) * 2 + 1));
+      bin2hex ((gdb_byte *) (utsv->name), buf.get (), strlen (utsv->name));
     }
 
   fprintf (writer->fp, "tsv %x:%s:%x:%s\n",
 	   utsv->number, phex_nz (utsv->initial_value, 8),
-	   utsv->builtin, buf != NULL ? buf : "");
-
-  if (utsv->name)
-    xfree (buf);
+	   utsv->builtin, buf != NULL ? buf.get () : "");
 }
 
 #define MAX_TRACE_UPLOAD 2000