GNOME Bugzilla – Bug 765959
socket: set fd field to -1 after closing socket
Last modified: 2016-05-04 13:49:43 UTC
We were leaving the fd to the no-longer valid fd. While accessing this after calling close is likely a programmer error, seems prudent to defend against. As there were no tests verifying that the fd should have been the same after closing, I'm inclined to believe it was not done on purpose.
Created attachment 327268 [details] [review] socket: set fd field to -1 after closing socket This ensures that g_socket_get_fd() will return -1 after the socket has been closed.
Created attachment 327269 [details] [review] socket: set fd field to -1 after closing socket This ensures that g_socket_get_fd() will return -1 after the socket has been closed.
Review of attachment 327269 [details] [review]: Seems ok to me. Did you hit this in a real-life situation somewhere ?
I was spelunking through gsocket while trying to track down an inf loop in bug 764823. Just something I noticed. Seems low priority at best.
Comment on attachment 327269 [details] [review] socket: set fd field to -1 after closing socket I can't think of any good reason why you'd want to call g_socket_get_fd() after closing the socket, but I can imagine people doing it for bad reasons maybe (using the fd as a hash table key?) so I'd say only commit this to master, not the stable branch just in case.
This problem has been fixed in the unstable development version. The fix will be available in the next major software release. You may need to upgrade your Linux distribution to obtain that newer version.