public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: John Baldwin <jhb@FreeBSD.org>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 3/5] Use gdb::unique_xmalloc_ptr<> instead of a deleter that invokes free().
Date: Thu, 04 Jan 2018 01:50:00 -0000	[thread overview]
Message-ID: <20180104014923.11899-4-jhb@FreeBSD.org> (raw)
In-Reply-To: <20180104014923.11899-1-jhb@FreeBSD.org>

Since xfree() always wraps free(), it is safe to use the xfree deleter
for buffers allocated by library routines such as kinfo_getvmmap() that
must be released via free().

gdb/ChangeLog:

	* fbsd-nat.c (struct free_deleter): Remove.
	(fbsd_find_memory_regions): Use gdb::unique_xmalloc_ptr<>.
---
 gdb/ChangeLog  |  5 +++++
 gdb/fbsd-nat.c | 10 +---------
 2 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 804dd4f402..cdce396e9c 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2018-01-03  John Baldwin  <jhb@FreeBSD.org>
+
+	* fbsd-nat.c (struct free_deleter): Remove.
+	(fbsd_find_memory_regions): Use gdb::unique_xmalloc_ptr<>.
+
 2018-01-03  John Baldwin  <jhb@FreeBSD.org>
 
 	* fbsd-nat.c (fbsd_pid_to_exec_file) [KERN_PROC_PATHNAME]: Return
diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c
index 7b1d1bf148..00e5cfb55c 100644
--- a/gdb/fbsd-nat.c
+++ b/gdb/fbsd-nat.c
@@ -78,14 +78,6 @@ fbsd_pid_to_exec_file (struct target_ops *self, int pid)
 }
 
 #ifdef HAVE_KINFO_GETVMMAP
-/* Deleter for std::unique_ptr that invokes free.  */
-
-template <typename T>
-struct free_deleter
-{
-  void operator() (T *ptr) const { free (ptr); }
-};
-
 /* Iterate over all the memory regions in the current inferior,
    calling FUNC for each memory region.  OBFD is passed as the last
    argument to FUNC.  */
@@ -99,7 +91,7 @@ fbsd_find_memory_regions (struct target_ops *self,
   uint64_t size;
   int i, nitems;
 
-  std::unique_ptr<struct kinfo_vmentry, free_deleter<struct kinfo_vmentry>>
+  gdb::unique_xmalloc_ptr<struct kinfo_vmentry>
     vmentl (kinfo_getvmmap (pid, &nitems));
   if (vmentl == NULL)
     perror_with_name (_("Couldn't fetch VM map entries."));
-- 
2.15.1

  parent reply	other threads:[~2018-01-04  1:50 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-04  1:50 [PATCH v2 0/5] Support for 'info proc' on FreeBSD cores and native John Baldwin
2018-01-04  1:50 ` [PATCH v2 1/5] Support 'info proc' for FreeBSD process core dumps John Baldwin
2018-01-05  2:54   ` Simon Marchi
2018-01-05 19:43     ` John Baldwin
2018-01-09 19:29       ` Simon Marchi
2018-01-04  1:50 ` John Baldwin [this message]
2018-01-05  2:58   ` [PATCH v2 3/5] Use gdb::unique_xmalloc_ptr<> instead of a deleter that invokes free() Simon Marchi
2018-01-04  1:50 ` [PATCH v2 2/5] Don't return stale data from fbsd_pid_to_exec_file for kernel processes John Baldwin
2018-01-05  2:57   ` Simon Marchi
2018-01-05 19:43     ` John Baldwin
2018-01-04  1:59 ` [PATCH v2 4/5] Support 'info proc' for native FreeBSD processes John Baldwin
2018-01-05  3:20   ` Simon Marchi
2018-01-05 19:43     ` John Baldwin
2018-01-04  1:59 ` [PATCH v2 5/5] Document support for 'info proc' on FreeBSD John Baldwin
2018-01-04 16:38   ` Eli Zaretskii
2018-01-04 21:36     ` John Baldwin
2018-01-05  6:53       ` Eli Zaretskii

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=20180104014923.11899-4-jhb@FreeBSD.org \
    --to=jhb@freebsd.org \
    --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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).