From ae026741df1a3f1dfe86ffde544010027a4c08b1 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Thu, 26 Nov 2015 00:24:21 +0000 Subject: [PATCH] re PR go/61303 (gccgo: segfault, regression since 4.8.2) 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 | 2 +- libgo/runtime/netpoll_select.c | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 9fe9d5e1042..80136abcf76 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -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. diff --git a/libgo/runtime/netpoll_select.c b/libgo/runtime/netpoll_select.c index b4613359118..033661d17f2 100644 --- a/libgo/runtime/netpoll_select.c +++ b/libgo/runtime/netpoll_select.c @@ -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; -- 2.30.2