public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/2] Replace xmalloc/xfree with vector in jit.c
@ 2019-12-11  6:38 Simon Marchi
  2019-12-11  6:38 ` [PATCH 2/2] Fix indentation " Simon Marchi
  2019-12-12 19:00 ` [PATCH 1/2] Replace xmalloc/xfree with vector " Tom Tromey
  0 siblings, 2 replies; 10+ messages in thread
From: Simon Marchi @ 2019-12-11  6:38 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2019-12-13 15:14 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-11  6:38 [PATCH 1/2] Replace xmalloc/xfree with vector in jit.c Simon Marchi
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).