public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH, committed] Fix issue with string options and nested gcc_jit_contexts
@ 2014-12-19 20:19 David Malcolm
  0 siblings, 0 replies; only message in thread
From: David Malcolm @ 2014-12-19 20:19 UTC (permalink / raw)
  To: gcc-patches, jit; +Cc: David Malcolm

The change to dynamically-allocated string options in r218617
introduced an issue with nested contexts, which were simply taking a
copy of the string pointer, rather than owning their own buffer.

Visible as various read-after-free errors when running
test-nested-contexts.c under valgrind, where a child context's dtor
would free the string option, but which would then be reused by a new
sibling context.

Fix it by creating new buffers for string options for child contexts.

Committed to trunk as r218972.

With this, jit.sum has:
  # of expected passes		4888

gcc/jit/ChangeLog:
	* jit-recording.c (gcc::jit::recording::context::context): When
	copying string options from a parent context, take a copy of the
	underlying buffers, rather than simply copying the pointer.
---
 gcc/jit/jit-recording.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/gcc/jit/jit-recording.c b/gcc/jit/jit-recording.c
index e52021d..d2b3a10 100644
--- a/gcc/jit/jit-recording.c
+++ b/gcc/jit/jit-recording.c
@@ -198,11 +198,14 @@ recording::context::context (context *parent_ctxt)
 
   if (parent_ctxt)
     {
-      /* Inherit options from parent.
-	 Note that the first memcpy means copying pointers to strings.  */
-      memcpy (m_str_options,
-	      parent_ctxt->m_str_options,
-	      sizeof (m_str_options));
+      /* Inherit options from parent.  */
+      for (unsigned i = 0;
+	   i < sizeof (m_str_options) / sizeof (m_str_options[0]);
+	   i++)
+	{
+	  const char *parent_opt = parent_ctxt->m_str_options[i];
+	  m_str_options[i] = parent_opt ? xstrdup (parent_opt) : NULL;
+	}
       memcpy (m_int_options,
 	      parent_ctxt->m_int_options,
 	      sizeof (m_int_options));
-- 
1.8.5.3

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-12-19 20:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-19 20:19 [PATCH, committed] Fix issue with string options and nested gcc_jit_contexts David Malcolm

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).