Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@polymtl.ca>
Subject: [PATCH 1/2] Replace xmalloc/xfree with vector in jit.c
Date: Wed, 11 Dec 2019 06:38:00 -0000	[thread overview]
Message-ID: <20191211063732.1043487-1-simon.marchi@polymtl.ca> (raw)

I'm currently studying that code and noticed this manual memory
management, which could easily be replaced with a vector, so here it is.

gdb/ChangeLog:

	* jit.c (jit_reader_try_read_symtab): Replace xmalloc/xfree with
	gdb::byte_vector.
---
 gdb/jit.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/gdb/jit.c b/gdb/jit.c
index 480b4596ac54..b6e51e4f8b4d 100644
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -808,7 +808,6 @@ static int
 jit_reader_try_read_symtab (struct jit_code_entry *code_entry,
                             CORE_ADDR entry_addr)
 {
-  gdb_byte *gdb_mem;
   int status;
   jit_dbg_reader_data priv_data;
   struct gdb_reader_funcs *funcs;
@@ -831,12 +830,12 @@ jit_reader_try_read_symtab (struct jit_code_entry *code_entry,
   if (!loaded_jit_reader)
     return 0;
 
-  gdb_mem = (gdb_byte *) xmalloc (code_entry->symfile_size);
+  gdb::byte_vector gdb_mem (code_entry->symfile_size);
 
   status = 1;
   try
     {
-      if (target_read_memory (code_entry->symfile_addr, gdb_mem,
+      if (target_read_memory (code_entry->symfile_addr, gdb_mem.data (),
 			      code_entry->symfile_size))
 	status = 0;
     }
@@ -848,12 +847,12 @@ jit_reader_try_read_symtab (struct jit_code_entry *code_entry,
   if (status)
     {
       funcs = loaded_jit_reader->functions;
-      if (funcs->read (funcs, &callbacks, gdb_mem, code_entry->symfile_size)
+      if (funcs->read (funcs, &callbacks, gdb_mem.data (),
+		       code_entry->symfile_size)
           != GDB_SUCCESS)
         status = 0;
     }
 
-  xfree (gdb_mem);
   if (jit_debug && status == 0)
     fprintf_unfiltered (gdb_stdlog,
                         "Could not read symtab using the loaded JIT reader.\n");
-- 
2.24.0


             reply	other threads:[~2019-12-11  6:38 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-11  6:38 Simon Marchi [this message]
2019-12-11  6:38 ` [PATCH 2/2] Fix indentation " Simon Marchi
2019-12-12 19:01   ` Tom Tromey
2019-12-12 19:54     ` Simon Marchi
2019-12-13  9:11     ` Strasuns, Mihails
2019-12-13  9:18       ` Eli Zaretskii
2019-12-13 14:43     ` Pedro Alves
2019-12-13 15:14       ` Simon Marchi
2019-12-12 19:00 ` [PATCH 1/2] Replace xmalloc/xfree with vector " Tom Tromey
2019-12-12 19:55   ` Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191211063732.1043487-1-simon.marchi@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox