main: Close the file descriptor we get from hook_connect().

We create a python socket object with fromfd() which duplicates the file
descriptor we get from hook_connect(). Close the unneeded file descriptor
instead of leaking it.
This commit is contained in:
Damir Jelić 2018-10-19 18:03:08 +02:00
parent 53b514809c
commit fbf56d3491

View file

@ -17,6 +17,7 @@
from __future__ import unicode_literals
import os
import socket
import ssl
import textwrap
@ -144,6 +145,10 @@ def wrap_socket(server, file_descriptor):
temp_socket = socket.fromfd(file_descriptor, socket.AF_INET,
socket.SOCK_STREAM)
# fromfd() duplicates the file descriptor, we can close the one we got from
# weechat now since we use the one from our socket when calling hook_fd()
os.close(file_descriptor)
# For python 2.7 wrap_socket() doesn't work with sockets created from an
# file descriptor because fromfd() doesn't return a wrapped socket, the bug
# was fixed for python 3, more info: https://bugs.python.org/issue13942