Karel Klic a2302b
diff -up emacs-23.3/src/xgselect.c.xgselect emacs-23.3/src/xgselect.c
Karel Klic a2302b
--- emacs-23.3/src/xgselect.c.xgselect	2011-11-25 14:05:03.963372281 +0100
Karel Klic a2302b
+++ emacs-23.3/src/xgselect.c	2011-11-25 14:06:49.798049160 +0100
Karel Klic a2302b
@@ -53,12 +53,17 @@ xg_select (max_fds, rfds, wfds, efds, ti
Karel Klic a2302b
   g_main_context_pending (context);
Karel Klic a2302b
 
Karel Klic a2302b
   do {
Karel Klic a2302b
-    if (n_gfds > gfds_size) 
Karel Klic a2302b
+    if (n_gfds > gfds_size)
Karel Klic a2302b
       {
Karel Klic a2302b
-        while (n_gfds > gfds_size) 
Karel Klic a2302b
-          gfds_size *= 2;
Karel Klic a2302b
-        xfree (gfds);
Karel Klic a2302b
-        gfds = xmalloc (sizeof (*gfds) * gfds_size);
Karel Klic a2302b
+	if (gfds_size == 0)
Karel Klic a2302b
+	  xgselect_initialize ();
Karel Klic a2302b
+	else
Karel Klic a2302b
+	  {
Karel Klic a2302b
+	    while (n_gfds > gfds_size)
Karel Klic a2302b
+	      gfds_size *= 2;
Karel Klic a2302b
+	    xfree (gfds);
Karel Klic a2302b
+	    gfds = xmalloc (sizeof (*gfds) * gfds_size);
Karel Klic a2302b
+	  }
Karel Klic a2302b
       }
Karel Klic a2302b
 
Karel Klic a2302b
     n_gfds = g_main_context_query (context,