GNOME Bugzilla – Bug 707912
g_io_stream_close() mishandles "pending"
Last modified: 2018-05-24 15:40:53 UTC
g_io_stream_close() calls g_io_stream_set_pending(), but the iostream-level pending flag is only used by g_io_stream_close() and g_io_stream_close_async(), so this has very little effect. In particular, you can close a GIOStream while simultaneously trying to perform an operation on its input or output streams (qv bug 707097, https://bugs.freedesktop.org/show_bug.cgi?id=64923), which most stream types don't actually handle correctly. Fixing this is not completely trivial, since g_io_stream_close() can't just call g_input_stream_set_pending() and g_output_stream_set_pending(), since that would break any giostream close implementations that just called g_input_stream_close() and g_output_stream_close(). One fix would be to make the pending flags be properties, and have GIOStream watch the pending properties of its child streams, and mark the iostream pending whenever either child stream is pending. However, the pending flags are frequently a pain in other situations where the implementation of one operation wants to call into another operation, so maybe a larger overhaul is in order. Eg, perhaps every GInputStream and GOutputStream method could have a "protected" _internal variant that assumed pending was already set, and then eg, g_input_stream_close() would be: gboolean g_input_stream_close (GInputStream *stream, GCancellable *cancellable, GError **error) { gboolean res; g_return_val_if_fail (G_IS_INPUT_STREAM (stream), FALSE); if (!g_input_stream_set_pending (stream, error)) return FALSE; res = g_input_stream_close_internal (stream, cancellable, error); g_input_stream_clear_pending (stream); return res; } and g_local_file_io_stream_close() would then call g_input_stream_close_internal() and g_output_stream_close_internal() rather than the public versions.
*** Bug 723655 has been marked as a duplicate of this bug. ***
Bug 723719 would need to be resolved before fixing this one causes a regression in gdbus.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/756.