[sgen] Don't crash in binary protocol flush when forcing.
authorMark Probst <mark.probst@gmail.com>
Thu, 31 Mar 2016 19:22:43 +0000 (12:22 -0700)
committerMark Probst <mark.probst@gmail.com>
Mon, 25 Jul 2016 18:06:55 +0000 (11:06 -0700)
mono/sgen/sgen-protocol.c
mono/sgen/sgen-protocol.h

index 2e59b6359a4b1aea6f4e650998ae1590e4318d50..ce504201f62d7ce42f8c0f5d64df086f7ed9d786 100644 (file)
@@ -262,27 +262,33 @@ binary_protocol_check_file_overflow (void)
  *
  * The protocol entries that do flush have `FLUSH()` in their definition.
  */
-void
+gboolean
 binary_protocol_flush_buffers (gboolean force)
 {
 #ifdef HAVE_UNISTD_H
        int num_buffers = 0, i;
+       BinaryProtocolBuffer *header;
        BinaryProtocolBuffer *buf;
        BinaryProtocolBuffer **bufs;
 
        if (binary_protocol_file == -1)
-               return;
+               return FALSE;
 
        if (!force && !try_lock_exclusive ())
-               return;
+               return FALSE;
 
-       for (buf = binary_protocol_buffers; buf != NULL; buf = buf->next)
+       header = binary_protocol_buffers;
+       for (buf = header; buf != NULL; buf = buf->next)
                ++num_buffers;
        bufs = (BinaryProtocolBuffer **)sgen_alloc_internal_dynamic (num_buffers * sizeof (BinaryProtocolBuffer*), INTERNAL_MEM_BINARY_PROTOCOL, TRUE);
-       for (buf = binary_protocol_buffers, i = 0; buf != NULL; buf = buf->next, i++)
+       for (buf = header, i = 0; buf != NULL; buf = buf->next, i++)
                bufs [i] = buf;
        SGEN_ASSERT (0, i == num_buffers, "Binary protocol buffer count error");
 
+       /*
+        * This might be incorrect when forcing, but all bets are off in that case, anyway,
+        * because we're trying to figure out a bug in the debugger.
+        */
        binary_protocol_buffers = NULL;
 
        for (i = num_buffers - 1; i >= 0; --i) {
@@ -294,6 +300,8 @@ binary_protocol_flush_buffers (gboolean force)
 
        if (!force)
                unlock_exclusive ();
+
+       return TRUE;
 #endif
 }
 
index 1c10d29d5c0e367f07e8d26a0163177da59c1b41..adefb98070bd5538b5d4a50442c311ef68dac853 100644 (file)
@@ -154,7 +154,7 @@ enum {
 void binary_protocol_init (const char *filename, long long limit);
 gboolean binary_protocol_is_enabled (void);
 
-void binary_protocol_flush_buffers (gboolean force);
+gboolean binary_protocol_flush_buffers (gboolean force);
 
 #define BEGIN_PROTOCOL_ENTRY0(method) \
        void method (void);