title: glib, (FIFO pipe) fd leak using GMainLoop and GSource timeout
body: <p>I've been having some issues with some file descriptors hanging when using Glibs GMainLoop.
  I've narrowed it down to a simple loop having one event.</p>
  
  <p>I'm monitoring the file descriptors when running the program and notice that there are a couple of file descriptors that never gets closed.</p>
  
  <p>Please see this example:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;glib.h&gt;
  #include &lt;gio/gio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;unistd.h&gt;
  
  static gboolean
  timeout(gpointer user_data)
  {
      printf("## %s\n", __FUNCTION__);
      g_main_loop_quit((GMainLoop*)user_data);
  }
  
  int
  main(int argc, char **argv)
  {
      g_type_init();
  
      printf("Check lsof now...\n");
      sleep(10);
      printf("--- time's up ---\n");
  
      GMainContext *ctx = g_main_context_new();
      GMainLoop *loop = g_main_loop_new(ctx, FALSE);
      g_main_context_push_thread_default(ctx);
  
      GSource *timer = g_timeout_source_new(2000);
      g_source_set_callback(timer, timeout, loop, NULL);
      g_source_attach(timer, ctx);
  
      g_main_loop_run(loop);
  
      g_main_context_pop_thread_default(ctx);
      g_source_unref(timer);
      g_main_loop_unref(loop);
      g_main_context_unref(ctx);
  
      printf("Check lsof now...\n");
      sleep(10);
      printf("--- time's up ---\n");
      return 0;
  }
  </code></pre>
  
  <p>Where it is marked in the code, I am checking the number of file descriptors the program has open. At the first checkpoint there are 3 (ignoring libs etc):</p>
  
  <pre><code>a.out   16333 hansm    0u   CHR 136,43      0t0      46 /dev/pts/43
  a.out   16333 hansm    1u   CHR 136,43      0t0      46 /dev/pts/43
  a.out   16333 hansm    2u   CHR 136,43      0t0      46 /dev/pts/43
  </code></pre>
  
  <p>At the second checkpoint there are five:</p>
  
  <pre><code>a.out   16873 hansm    0u   CHR 136,43      0t0        46 /dev/pts/43
  a.out   16873 hansm    1u   CHR 136,43      0t0        46 /dev/pts/43
  a.out   16873 hansm    2u   CHR 136,43      0t0        46 /dev/pts/43
  a.out   16873 hansm    5r  FIFO    0,8      0t0 149228995 pipe
  a.out   16873 hansm    6w  FIFO    0,8      0t0 149228995 pipe
  </code></pre>
  
  <p>Why are these pipes not closed?</p>
  
  <p>Valgrind reports no error (except some 'possibly lost memory').</p>
  
  <p>The fd's (5 and 6 in example above) are opened when doing</p>
  
  <pre><code>GMainContext *ctx = g_main_context_new();
  </code></pre>
  
  <p>And obviously never closed. What am I doing wrong?</p>