gtk_source_remove() hangs



I'm writting my first GTK based program, and it basically
works except for what appears to be a very slow memory leak
and the occasional hang.

Its the hang I'm most concerned with.

My app creates a socket listener...

The parent creates a child process,
when the child powers up, it connects to that listener.
The parent then exchanges stuff with the child through that
socket, and when the child dies, I close the socket.

The the whole sequence repeats again...


In sorta psuedo code, the listener creation is the usual:

 listener_fd = socket();
 bind(listener_fd);
 listen(listener_fd);

followed by:

 listener_channel = g_io_channel_unix_new(listener_fd);
listener_id = g_io_add_watch(listener_channel), G_IO_IN, wait_for_child_connection, "");

 wait_for_child_connection(GIOChannel *source, ...) {
   child_fd = accept(g_io_channel_unix_get_fd(source), ...);
   child_id = g_io_add_watch(child_channel, GIO_IN, process_message "");
   return TRUE;
 }

Then when the child dies and I catch the SIGCHLD, I do the following:

 if (child_id != 0) { gsource_remove(child_id); child_id = 0; }
 if (child_channel != NULL) {
   gio_channel_shutdown(child_channel, TRUE, &error);
   g_io_channel_unref(child_channel);
   child_channel = NULL;
 }
 if (child_fd != 0) { close)child_fd); }

============================

What I find is that at random, and fairly rarely, the app hangs
in the middle of the g_source_remove() funcation, cause it never
returns.

- Is this not the correct way to handle it?
- Or am I doing something wrong?
- Or is related to the fact that the other end of the socket has already died? - And could this code be somehow related to the minor memory leak I still have?


Any help would be appreciated.

TIA
Fulko






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]