File tree 1 file changed +12
-2
lines changed
1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -383,10 +383,20 @@ typedef enum {
383
383
#define ERRSTR1 (x ,y ,z ) (x ":" y ": " z)
384
384
#define ERRSTR (x ) ERRSTR1("_ssl.c", Py_STRINGIFY(__LINE__), x)
385
385
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.
387
388
static inline PySocketSockObject * GET_SOCKET (PySSLSocket * obj ) {
388
389
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
390
400
}
391
401
else {
392
402
return NULL ;
You can’t perform that action at this time.
0 commit comments