re PR go/61303 (gccgo: segfault, regression since 4.8.2)
authorIan Lance Taylor <ian@gcc.gnu.org>
Thu, 26 Nov 2015 00:24:21 +0000 (00:24 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Thu, 26 Nov 2015 00:24:21 +0000 (00:24 +0000)
PR go/61303
    runtime: don't overallocate in select code

    If we've already allocated an fd_set, don't allocate another one.

    Also, don't bother to read from rdwake if it wasn't returned in select.

    Fixes https://gcc.gnu.org/PR61303.

    Reviewed-on: https://go-review.googlesource.com/17243

From-SVN: r230922

gcc/go/gofrontend/MERGE
libgo/runtime/netpoll_select.c

index 9fe9d5e1042de9814624164490cfc75ab880309b..80136abcf76c0804a99c65eff00c10eb888f6f00 100644 (file)
@@ -1,4 +1,4 @@
-0d979f0b860cfd879754150e0ae5e1018b94d7c4
+81eb6a3f425b2158c67ee32c0cc973a72ce9d6be
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
index b46133591184c7cdc7ef1e78676b0515dc7243c4..033661d17f243134f3656d3e1f8d02dd4946abf4 100644 (file)
@@ -135,6 +135,8 @@ runtime_netpoll(bool block)
        byte b;
        struct stat st;
 
+       allocatedfds = false;
+
  retry:
        runtime_lock(&selectlock);
 
@@ -146,11 +148,13 @@ runtime_netpoll(bool block)
        }
 
        if(inuse) {
-               prfds = runtime_SysAlloc(4 * sizeof fds, &mstats.other_sys);
-               pwfds = prfds + 1;
-               pefds = pwfds + 1;
-               ptfds = pefds + 1;
-               allocatedfds = true;
+               if(!allocatedfds) {
+                       prfds = runtime_SysAlloc(4 * sizeof fds, &mstats.other_sys);
+                       pwfds = prfds + 1;
+                       pefds = pwfds + 1;
+                       ptfds = pefds + 1;
+                       allocatedfds = true;
+               }
        } else {
                prfds = &grfds;
                pwfds = &gwfds;
@@ -216,7 +220,7 @@ runtime_netpoll(bool block)
                        mode = 'r' + 'w';
                        --c;
                }
-               if(i == rdwake) {
+               if(i == rdwake && mode != 0) {
                        while(read(rdwake, &b, sizeof b) > 0)
                                ;
                        continue;