File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -383,10 +383,20 @@ typedef enum {
383383#define ERRSTR1 (x ,y ,z ) (x ":" y ": " z)
384384#define ERRSTR (x ) ERRSTR1("_ssl.c", Py_STRINGIFY(__LINE__), x)
385385
386- /* Get the socket from a PySSLSocket, if it has one */
386+ // Get the socket from a PySSLSocket, if it has one.
387+ // Return a borrowed reference.
387388static inline PySocketSockObject * GET_SOCKET (PySSLSocket * obj ) {
388389 if (obj -> Socket ) {
389- return (PySocketSockObject * )PyWeakref_GetObject (obj -> Socket );
390+ PyObject * sock = _PyWeakref_GET_REF (obj -> Socket );
391+ if (sock != NULL ) {
392+ // GET_SOCKET() returns a borrowed reference
393+ Py_DECREF (sock );
394+ }
395+ else {
396+ // dead weak reference
397+ sock = Py_None ;
398+ }
399+ return (PySocketSockObject * )sock ; // borrowed reference
390400 }
391401 else {
392402 return NULL ;
You can’t perform that action at this time.
0 commit comments