public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Simplify write_inferior_memory
@ 2019-08-15 13:42 Tom Tromey
0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2019-08-15 13:42 UTC (permalink / raw)
To: gdb-cvs
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=c6778d00df0fbc7fe53801717eb934a5d7b9674a
commit c6778d00df0fbc7fe53801717eb934a5d7b9674a
Author: Tom Tromey <tromey@adacore.com>
Date: Wed Aug 14 09:11:28 2019 -0600
Simplify write_inferior_memory
gdbserver's write_inferior_memory uses a static variable to avoid
memory leaks, and has a comment referring to the lack of cleanups.
This patch removes this comment and the code in favor of a
straightforward use of std::vector.
gdb/gdbserver/ChangeLog
2019-08-15 Tom Tromey <tromey@adacore.com>
* target.c (write_inferior_memory): Use std::vector.
Diff:
---
gdb/gdbserver/ChangeLog | 4 ++++
gdb/gdbserver/target.c | 22 +++++-----------------
2 files changed, 9 insertions(+), 17 deletions(-)
diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog
index 2dda352..e4ad220 100644
--- a/gdb/gdbserver/ChangeLog
+++ b/gdb/gdbserver/ChangeLog
@@ -1,3 +1,7 @@
+2019-08-15 Tom Tromey <tromey@adacore.com>
+
+ * target.c (write_inferior_memory): Use std::vector.
+
2019-08-06 Frank Ch. Eigler <fche@redhat.com>
PR build/24886
diff --git a/gdb/gdbserver/target.c b/gdb/gdbserver/target.c
index 25f91ee..2587d8a 100644
--- a/gdb/gdbserver/target.c
+++ b/gdb/gdbserver/target.c
@@ -150,23 +150,11 @@ int
write_inferior_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
int len)
{
- /* Lacking cleanups, there is some potential for a memory leak if the
- write fails and we go through error(). Make sure that no more than
- one buffer is ever pending by making BUFFER static. */
- static unsigned char *buffer = 0;
- int res;
-
- if (buffer != NULL)
- free (buffer);
-
- buffer = (unsigned char *) xmalloc (len);
- memcpy (buffer, myaddr, len);
- check_mem_write (memaddr, buffer, myaddr, len);
- res = (*the_target->write_memory) (memaddr, buffer, len);
- free (buffer);
- buffer = NULL;
-
- return res;
+ /* Make a copy of the data because check_mem_write may need to
+ update it. */
+ std::vector<unsigned char> buffer (myaddr, myaddr + len);
+ check_mem_write (memaddr, buffer.data (), myaddr, len);
+ return (*the_target->write_memory) (memaddr, buffer.data (), len);
}
/* See target/target.h. */
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2019-08-15 13:42 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-15 13:42 [binutils-gdb] Simplify write_inferior_memory Tom Tromey
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).