From 3bf8db999bd8857a1f8ae10dafe09182f68be58f Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Thu, 4 Jul 2013 20:02:20 -0600 Subject: [PATCH] avoid SAFE_ALLOCA avoid SAFE_ALLOCA in xgselect.c. in this code it is just as easy to always use malloc; and it avoids thread-switching problems, as the safe-alloca stuff implicitly refers to the current thread --- src/xgselect.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/xgselect.c b/src/xgselect.c index 4d90298a9d9..15ee59dfa81 100644 --- a/src/xgselect.c +++ b/src/xgselect.c @@ -40,8 +40,7 @@ xg_select (int fds_lim, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds, GPollFD *gfds = gfds_buf; int gfds_size = sizeof gfds_buf / sizeof *gfds_buf; int n_gfds, retval = 0, our_fds = 0, max_fds = fds_lim - 1; - int i, nfds, tmo_in_millisec; - USE_SAFE_ALLOCA; + int i, nfds, tmo_in_millisec, must_free = 0; /* Do not try to optimize with an initial check with g_main_context_pending and a call to pselect if it returns false. If Gdk has a timeout for 0.01 @@ -60,7 +59,8 @@ xg_select (int fds_lim, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds, gfds, gfds_size); if (gfds_size < n_gfds) { - SAFE_NALLOCA (gfds, sizeof *gfds, n_gfds); + gfds = xnmalloc (n_gfds, sizeof *gfds); + must_free = 1; gfds_size = n_gfds; n_gfds = g_main_context_query (context, G_PRIORITY_LOW, &tmo_in_millisec, gfds, gfds_size); @@ -81,7 +81,8 @@ xg_select (int fds_lim, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds, } } - SAFE_FREE (); + if (must_free) + xfree (gfds); if (tmo_in_millisec >= 0) { -- 2.39.5