GTlsConnections were never being freed, due to circular refs.
Additionally, certificates seen during handshaking, and a
GSocketAddress used in the session cache code were being leaked.
gnutls->priv->session_id = g_strdup_printf ("%s/%d", addrstr, port);
g_free (addrstr);
}
+ g_object_unref (remote_addr);
}
g_object_unref (base_conn);
for (i = num_certs - 1; i >= 0; i--)
{
cert = g_tls_certificate_gnutls_new (&certs[i], chain);
+ if (chain)
+ g_object_unref (chain);
chain = cert;
}
}
};
static void
-g_tls_input_stream_gnutls_finalize (GObject *object)
+g_tls_input_stream_gnutls_dispose (GObject *object)
{
GTlsInputStreamGnutls *stream = G_TLS_INPUT_STREAM_GNUTLS (object);
if (stream->priv->conn)
- g_object_unref (stream->priv->conn);
+ {
+ g_object_remove_weak_pointer (G_OBJECT (stream->priv->conn),
+ (gpointer *)&stream->priv->conn);
+ stream->priv->conn = NULL;
+ }
- G_OBJECT_CLASS (g_tls_input_stream_gnutls_parent_class)->finalize (object);
+ G_OBJECT_CLASS (g_tls_input_stream_gnutls_parent_class)->dispose (object);
}
static gssize
{
GTlsInputStreamGnutls *tls_stream = G_TLS_INPUT_STREAM_GNUTLS (stream);
+ g_return_val_if_fail (tls_stream->priv->conn != NULL, -1);
+
return g_tls_connection_gnutls_read (tls_stream->priv->conn,
buffer, count, TRUE,
cancellable, error);
GError *error = NULL;
GSource *source;
+ g_return_if_fail (tls_stream->priv->conn != NULL);
+
simple = g_simple_async_result_new (G_OBJECT (stream), callback, user_data,
g_tls_input_stream_gnutls_read_async);
nread = g_tls_connection_gnutls_read (tls_stream->priv->conn,
{
GTlsInputStreamGnutls *tls_stream = G_TLS_INPUT_STREAM_GNUTLS (pollable);
+ g_return_val_if_fail (tls_stream->priv->conn != NULL, FALSE);
+
return g_tls_connection_gnutls_check (tls_stream->priv->conn, G_IO_IN);
}
{
GTlsInputStreamGnutls *tls_stream = G_TLS_INPUT_STREAM_GNUTLS (pollable);
+ g_return_val_if_fail (tls_stream->priv->conn != NULL, NULL);
+
return g_tls_connection_gnutls_create_source (tls_stream->priv->conn,
G_IO_IN,
cancellable);
g_type_class_add_private (klass, sizeof (GTlsInputStreamGnutlsPrivate));
- gobject_class->finalize = g_tls_input_stream_gnutls_finalize;
+ gobject_class->dispose = g_tls_input_stream_gnutls_dispose;
input_stream_class->read_fn = g_tls_input_stream_gnutls_read;
input_stream_class->read_async = g_tls_input_stream_gnutls_read_async;
GTlsInputStreamGnutls *tls_stream;
tls_stream = g_object_new (G_TYPE_TLS_INPUT_STREAM_GNUTLS, NULL);
- tls_stream->priv->conn = g_object_ref (conn);
+ tls_stream->priv->conn = conn;
+ g_object_add_weak_pointer (G_OBJECT (conn),
+ (gpointer *)&tls_stream->priv->conn);
+
return G_INPUT_STREAM (tls_stream);
}
};
static void
-g_tls_output_stream_gnutls_finalize (GObject *object)
+g_tls_output_stream_gnutls_dispose (GObject *object)
{
GTlsOutputStreamGnutls *stream = G_TLS_OUTPUT_STREAM_GNUTLS (object);
if (stream->priv->conn)
- g_object_unref (stream->priv->conn);
+ {
+ g_object_remove_weak_pointer (G_OBJECT (stream->priv->conn),
+ (gpointer *)&stream->priv->conn);
+ stream->priv->conn = NULL;
+ }
- G_OBJECT_CLASS (g_tls_output_stream_gnutls_parent_class)->finalize (object);
+ G_OBJECT_CLASS (g_tls_output_stream_gnutls_parent_class)->dispose (object);
}
static gssize
{
GTlsOutputStreamGnutls *tls_stream = G_TLS_OUTPUT_STREAM_GNUTLS (stream);
+ g_return_val_if_fail (tls_stream->priv->conn != NULL, -1);
+
return g_tls_connection_gnutls_write (tls_stream->priv->conn,
buffer, count, TRUE,
cancellable, error);
GError *error = NULL;
GSource *source;
+ g_return_if_fail (tls_stream->priv->conn != NULL);
+
simple = g_simple_async_result_new (G_OBJECT (stream), callback, user_data,
g_tls_output_stream_gnutls_write_async);
nwrote = g_tls_connection_gnutls_write (tls_stream->priv->conn,
{
GTlsOutputStreamGnutls *tls_stream = G_TLS_OUTPUT_STREAM_GNUTLS (pollable);
+ g_return_val_if_fail (tls_stream->priv->conn != NULL, FALSE);
+
return g_tls_connection_gnutls_check (tls_stream->priv->conn, G_IO_OUT);
}
{
GTlsOutputStreamGnutls *tls_stream = G_TLS_OUTPUT_STREAM_GNUTLS (pollable);
+ g_return_val_if_fail (tls_stream->priv->conn != NULL, NULL);
+
return g_tls_connection_gnutls_create_source (tls_stream->priv->conn,
G_IO_OUT,
cancellable);
g_type_class_add_private (klass, sizeof (GTlsOutputStreamGnutlsPrivate));
- gobject_class->finalize = g_tls_output_stream_gnutls_finalize;
+ gobject_class->dispose = g_tls_output_stream_gnutls_dispose;
output_stream_class->write_fn = g_tls_output_stream_gnutls_write;
output_stream_class->write_async = g_tls_output_stream_gnutls_write_async;
GTlsOutputStreamGnutls *tls_stream;
tls_stream = g_object_new (G_TYPE_TLS_OUTPUT_STREAM_GNUTLS, NULL);
- tls_stream->priv->conn = g_object_ref (conn);
+ tls_stream->priv->conn = conn;
+ g_object_add_weak_pointer (G_OBJECT (conn),
+ (gpointer *)&tls_stream->priv->conn);
+
return G_OUTPUT_STREAM (tls_stream);
}