Skip to content

gh-108240: Fix a reference cycle in _socket.CAPI capsule #108241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Modules/socketmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -7317,7 +7317,6 @@ os_init(void)
static void
sock_free_api(PySocketModule_APIObject *capi)
{
Py_DECREF(capi->Sock_Type);
Py_DECREF(capi->error);
Py_DECREF(capi->timeout_error);
PyMem_Free(capi);
Expand All @@ -7339,7 +7338,7 @@ sock_get_api(socket_state *state)
return NULL;
}

capi->Sock_Type = (PyTypeObject *)Py_NewRef(state->sock_type);
capi->Sock_Type = state->sock_type;
capi->error = Py_NewRef(PyExc_OSError);
capi->timeout_error = Py_NewRef(PyExc_TimeoutError);
return capi;
Expand Down
2 changes: 1 addition & 1 deletion Modules/socketmodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ typedef struct {
/* C API for usage by other Python modules.
* Always add new things to the end for binary compatibility. */
typedef struct {
PyTypeObject *Sock_Type;
PyTypeObject *Sock_Type; // borrowed reference (gh-108240)
PyObject *error;
PyObject *timeout_error;
} PySocketModule_APIObject;
Expand Down