[v2,11/22] Use unique_xmalloc_ptr in remote.c

Message ID 20190227201849.32210-12-tom@tromey.com
State New, archived
Headers

Commit Message

Tom Tromey Feb. 27, 2019, 8:18 p.m. UTC
  This removes a cleanup from remote.c, replacing it with
unique_xmalloc_ptr.

gdb/ChangeLog
2019-02-27  Tom Tromey  <tom@tromey.com>

	* remote.c (remote_target::remote_parse_stop_reply): Use
	unique_xmalloc_ptr.
---
 gdb/ChangeLog |  5 +++++
 gdb/remote.c  | 11 +++++------
 2 files changed, 10 insertions(+), 6 deletions(-)
  

Comments

Pedro Alves March 6, 2019, 9:16 p.m. UTC | #1
On 02/27/2019 08:18 PM, Tom Tromey wrote:
> This removes a cleanup from remote.c, replacing it with
> unique_xmalloc_ptr.
> 
> gdb/ChangeLog
> 2019-02-27  Tom Tromey  <tom@tromey.com>
> 
> 	* remote.c (remote_target::remote_parse_stop_reply): Use
> 	unique_xmalloc_ptr.
> ---
>  gdb/ChangeLog |  5 +++++
>  gdb/remote.c  | 11 +++++------
>  2 files changed, 10 insertions(+), 6 deletions(-)
> 
> diff --git a/gdb/remote.c b/gdb/remote.c
> index f80dcdaee94..5f658deefaa 100644
> --- a/gdb/remote.c
> +++ b/gdb/remote.c
> @@ -7314,14 +7314,13 @@ Packet: '%s'\n"),
>  
>  	      /* Save the pathname for event reporting and for
>  		 the next run command.  */
> -	      char *pathname = (char *) xmalloc (pathlen + 1);
> -	      struct cleanup *old_chain = make_cleanup (xfree, pathname);
> -	      hex2bin (p1, (gdb_byte *) pathname, pathlen);
> -	      pathname[pathlen] = '\0';
> -	      discard_cleanups (old_chain);
> +	      gdb::unique_xmalloc_ptr<char> pathname
> +		((char *) xmalloc (pathlen + 1));

Use:

	      gdb::unique_xmalloc_ptr<char[]>


> +	      hex2bin (p1, (gdb_byte *) pathname.get (), pathlen);
> +	      pathname.get ()[pathlen] = '\0';

Then here write:

	      pathname[pathlen] = '\0';

Otherwise OK.

Thanks,
Pedro Alves
  

Patch

diff --git a/gdb/remote.c b/gdb/remote.c
index f80dcdaee94..5f658deefaa 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -7314,14 +7314,13 @@  Packet: '%s'\n"),
 
 	      /* Save the pathname for event reporting and for
 		 the next run command.  */
-	      char *pathname = (char *) xmalloc (pathlen + 1);
-	      struct cleanup *old_chain = make_cleanup (xfree, pathname);
-	      hex2bin (p1, (gdb_byte *) pathname, pathlen);
-	      pathname[pathlen] = '\0';
-	      discard_cleanups (old_chain);
+	      gdb::unique_xmalloc_ptr<char> pathname
+		((char *) xmalloc (pathlen + 1));
+	      hex2bin (p1, (gdb_byte *) pathname.get (), pathlen);
+	      pathname.get ()[pathlen] = '\0';
 
 	      /* This is freed during event handling.  */
-	      event->ws.value.execd_pathname = pathname;
+	      event->ws.value.execd_pathname = pathname.release ();
 	      event->ws.kind = TARGET_WAITKIND_EXECD;
 
 	      /* Skip the registers included in this packet, since