[gnome-mud] mud-connection: Remove sources when finalized
- From: Mart Raudsepp <mraudsepp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-mud] mud-connection: Remove sources when finalized
- Date: Wed, 8 Nov 2017 02:40:01 +0000 (UTC)
commit 3458d6050b5d22922e5d16b26a25969253f097d4
Author: Steven Joruk <sjoruk gmail com>
Date: Tue Nov 7 16:21:52 2017 +0000
mud-connection: Remove sources when finalized
This fixes a crash when closing connection views and follows the advice
of the glib "memory management of sources" documentation.
src/mud-connection.c | 10 +++++++++-
1 files changed, 9 insertions(+), 1 deletions(-)
---
diff --git a/src/mud-connection.c b/src/mud-connection.c
index d883130..eca0807 100644
--- a/src/mud-connection.c
+++ b/src/mud-connection.c
@@ -36,6 +36,7 @@ struct _MudConnection
GByteArray *outbuf;
GSocketConnection *scon;
GSocket *socket;
+ guint read_source_id;
GSource *write_source;
};
@@ -73,6 +74,12 @@ mud_connection_finalize(GObject *object)
if(self->scon)
g_io_stream_close(G_IO_STREAM(self->scon), NULL, NULL);
+ if(self->read_source_id > 0)
+ g_source_remove(self->read_source_id);
+
+ if(self->write_source)
+ g_source_remove(g_source_get_id(self->write_source));
+
G_OBJECT_CLASS(mud_connection_parent_class)->finalize(object);
}
@@ -123,6 +130,7 @@ mud_connection_init(MudConnection *self)
self->outbuf = g_byte_array_sized_new(BUFFER_RESERVE);
self->scon = NULL;
self->socket = NULL;
+ self->read_source_id = 0;
self->write_source = NULL;
}
@@ -294,7 +302,7 @@ socket_client_connect_cb(GObject *source_object, GAsyncResult *res,
source = g_socket_create_source(self->socket, G_IO_IN, NULL);
g_source_set_callback(source, (GSourceFunc)socket_read_ready_cb, self, NULL);
g_source_set_can_recurse(source, FALSE);
- g_source_attach(source, NULL);
+ self->read_source_id = g_source_attach(source, NULL);
g_source_unref(source);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]