This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Add missing cleanup to remote_query_supported, use reconcat.


There's a cleanup missing in remote_query_supported, to
release the temporary qSupported string, if putpkt throws.
While there, we can use reconcat to simplify the code
a bit.  reconcat is to concat, like realloc is to malloc.

No regressions against a local x86_64-linux gdbserver (target remote),
and also ran the gdb.server/ (in otherwise native testing), to cover
extended-remote.

Applied.

-- 
Pedro Alves

2010-05-07  Pedro Alves  <pedro@codesourcery.com>

	* remote.c (remote_query_supported_append): Use reconcat.
	(remote_query_supported): Install a cleanup.  Use reconcat.

---
 gdb/remote.c |   21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

Index: src/gdb/remote.c
===================================================================
--- src.orig/gdb/remote.c	2010-05-07 14:11:32.000000000 +0100
+++ src/gdb/remote.c	2010-05-07 14:34:02.000000000 +0100
@@ -3523,9 +3523,9 @@ register_remote_support_xml (const char 
       while ((p = strtok (NULL, ",")) != NULL);
       xfree (copy);
 
-      p = concat (remote_support_xml, ",", xml, (char *) NULL);
-      xfree (remote_support_xml);
-      remote_support_xml = p;
+      remote_support_xml = reconcat (remote_support_xml,
+				     remote_support_xml, ",", xml,
+				     (char *) NULL);
     }
 #endif
 }
@@ -3534,11 +3534,7 @@ static char *
 remote_query_supported_append (char *msg, const char *append)
 {
   if (msg)
-    {
-      char *p = concat (msg, ";", append, (char *) NULL);
-      xfree (msg);
-      return p;
-    }
+    return reconcat (msg, msg, ";", append, (char *) NULL);
   else
     return xstrdup (append);
 }
@@ -3562,6 +3558,7 @@ remote_query_supported (void)
   if (remote_protocol_packets[PACKET_qSupported].support != PACKET_DISABLE)
     {
       char *q = NULL;
+      struct cleanup *old_chain = make_cleanup (free_current_contents, &q);
 
       if (rs->extended)
 	q = remote_query_supported_append (q, "multiprocess+");
@@ -3571,14 +3568,14 @@ remote_query_supported (void)
 
       if (q)
 	{
-	  char *p = concat ("qSupported:", q, (char *) NULL);
-	  xfree (q);
-	  putpkt (p);
-	  xfree (p);
+	  q = reconcat (q, "qSupported:", q, (char *) NULL);
+	  putpkt (q);
 	}
       else
 	putpkt ("qSupported");
 
+      do_cleanups (old_chain);
+
       getpkt (&rs->buf, &rs->buf_size, 0);
 
       /* If an error occured, warn, but do not return - just reset the


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]