From patchwork Wed Dec 11 06:37:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 36707 Received: (qmail 8593 invoked by alias); 11 Dec 2019 06:38:11 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 8585 invoked by uid 89); 11 Dec 2019 06:38:11 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_SOFTFAIL autolearn=ham version=3.3.1 spammy=management, HContent-Transfer-Encoding:8bit X-HELO: barracuda.ebox.ca Received: from barracuda.ebox.ca (HELO barracuda.ebox.ca) (96.127.255.19) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 11 Dec 2019 06:38:10 +0000 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id bfCPUnLTMDGUo7EZ (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 11 Dec 2019 01:37:33 -0500 (EST) Received: from simark.lan (unknown [192.222.164.54]) by smtp.ebox.ca (Postfix) with ESMTP id 3228E441D64; Wed, 11 Dec 2019 01:37:33 -0500 (EST) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 1/2] Replace xmalloc/xfree with vector in jit.c Date: Wed, 11 Dec 2019 01:37:31 -0500 Message-Id: <20191211063732.1043487-1-simon.marchi@polymtl.ca> MIME-Version: 1.0 X-IsSubscribed: yes 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");