After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 730188 - gsocket: Document FD ownership with g_socket_new_from_fd()
gsocket: Document FD ownership with g_socket_new_from_fd()
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: network
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2014-05-15 11:47 UTC by Philip Withnall
Modified: 2015-03-21 17:38 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gsocket: Document FD ownership with g_socket_new_from_fd() (858 bytes, patch)
2014-05-15 11:47 UTC, Philip Withnall
none Details | Review

Description Philip Withnall 2014-05-15 11:47:02 UTC
Patch attached.
Comment 1 Philip Withnall 2014-05-15 11:47:04 UTC
Created attachment 276597 [details] [review]
gsocket: Document FD ownership with g_socket_new_from_fd()
Comment 2 Allison Karlitskaya (desrt) 2014-05-25 09:33:57 UTC
Are you sure?

It looks like if we fail during g_socket_details_from_fd() then we still have the fd in socket->priv->fd... we will then close it in finalize() when we destroy the half-created object.
Comment 3 Philip Withnall 2014-05-26 07:37:44 UTC
(In reply to comment #2)
> Are you sure?
> 
> It looks like if we fail during g_socket_details_from_fd() then we still have
> the fd in socket->priv->fd... we will then close it in finalize() when we
> destroy the half-created object.

As I read it, the check_socket() call at the top of g_socket_close() will bail out because either:
 • !priv->inited; or
 • priv->construct_error != NULL
leaving the FD open.
Comment 4 Dan Winship 2014-06-07 12:23:22 UTC
(In reply to comment #3)
> As I read it, the check_socket() call at the top of g_socket_close() will bail
> out because either:
>  • !priv->inited; or
>  • priv->construct_error != NULL
> leaving the FD open.

Indeed... so the question now is whether that is a bug or not.

I guess there might be some code assuming the current behavior so it's probably best to preserve it?
Comment 5 Philip Withnall 2014-06-16 08:46:41 UTC
(In reply to comment #4)
> (In reply to comment #3)
> > As I read it, the check_socket() call at the top of g_socket_close() will bail
> > out because either:
> >  • !priv->inited; or
> >  • priv->construct_error != NULL
> > leaving the FD open.
> 
> Indeed... so the question now is whether that is a bug or not.
> 
> I guess there might be some code assuming the current behavior so it's probably
> best to preserve it?

If I remember correctly I originally did a version of this patch which did close the FD, and I found that it was causing errors in a few places where existing code does assume the current behaviour. So I think we (unfortunately) do need to preserve it.
Comment 6 Dan Winship 2015-03-21 17:38:16 UTC
committed the docs patch to master and glib-2-44