Skip to content

Commit

Permalink
Merge pull request #516 from skirpichev/fix-memleak-ctx-exit-515
Browse files Browse the repository at this point in the history
Fix memory leak in GMPy_CTXT_Exit()
  • Loading branch information
casevh authored Sep 14, 2024
2 parents a3f991c + 13efb8a commit 9177648
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/gmpy2_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ GMPy_CTXT_Enter(PyObject *self, PyObject *args)
static PyObject *
GMPy_CTXT_Exit(PyObject *self, PyObject *args)
{
int res = PyContextVar_Reset(current_context_var, ((CTXT_Object*)self)->token);
CTXT_Object *ctx = (CTXT_Object*)self;
int res = PyContextVar_Reset(current_context_var, ctx->token);
Py_DECREF(ctx->token);
if (res == -1) {
SYSTEM_ERROR("Unexpected failure in restoring context.");
return NULL;
Expand Down

0 comments on commit 9177648

Please sign in to comment.