[binutils-gdb] gdb: (de-)allocate target_desc_info with new/delete

Simon Marchi simark@sourceware.org
Fri May 7 20:29:48 GMT 2021


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=0b2f7ade5352e698ded54760ee8b34092fdd164f

commit 0b2f7ade5352e698ded54760ee8b34092fdd164f
Author: Simon Marchi <simon.marchi@polymtl.ca>
Date:   Fri May 7 16:28:56 2021 -0400

    gdb: (de-)allocate target_desc_info with new/delete
    
    In preparation for using non-POD types in the struct.
    
    gdb/ChangeLog:
    
            * target-descriptions.c (struct target_desc_info): Initialize
            fields.
            (get_tdesc_info): Use new.
            (target_desc_info_free): Use delete.
    
    Change-Id: I10fdaeeae7cdbd7930ae7adeeb13f7f363c67c7a

Diff:
---
 gdb/ChangeLog             |  7 +++++++
 gdb/target-descriptions.c | 11 ++++++-----
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 604403c59cd..e9c515640f3 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@
+2021-05-07  Simon Marchi  <simon.marchi@polymtl.ca>
+
+	* target-descriptions.c (struct target_desc_info): Initialize
+	fields.
+	(get_tdesc_info): Use new.
+	(target_desc_info_free): Use delete.
+
 2021-05-07  Simon Marchi  <simon.marchi@polymtl.ca>
 
 	* target-descriptions.c (struct target_desc_info) <fetched>:
diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c
index 78dc89ac99f..4e0846a1a0b 100644
--- a/gdb/target-descriptions.c
+++ b/gdb/target-descriptions.c
@@ -446,7 +446,7 @@ struct target_desc_info
   /* A flag indicating that a description has already been fetched
      from the target, so it should not be queried again.  */
 
-  bool fetched;
+  bool fetched = false;
 
   /* The description fetched from the target, or NULL if the target
      did not supply any description.  Only valid when
@@ -454,12 +454,12 @@ struct target_desc_info
      code should access this; normally, the description should be
      accessed through the gdbarch object.  */
 
-  const struct target_desc *tdesc;
+  const struct target_desc *tdesc = nullptr;
 
   /* The filename to read a target description from, as set by "set
      tdesc filename ..."  */
 
-  char *filename;
+  char *filename = nullptr;
 };
 
 /* Get the inferior INF's target description info, allocating one on
@@ -469,7 +469,8 @@ static struct target_desc_info *
 get_tdesc_info (struct inferior *inf)
 {
   if (inf->tdesc_info == NULL)
-    inf->tdesc_info = XCNEW (struct target_desc_info);
+    inf->tdesc_info = new target_desc_info;
+
   return inf->tdesc_info;
 }
 
@@ -507,7 +508,7 @@ target_desc_info_free (struct target_desc_info *tdesc_info)
   if (tdesc_info != NULL)
     {
       xfree (tdesc_info->filename);
-      xfree (tdesc_info);
+      delete tdesc_info;
     }
 }


More information about the Gdb-cvs mailing list