Skip to content

Commit cc40c8f

Browse files
committed
Fix refcounting in example
1 parent 364ae9c commit cc40c8f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

peps/pep-0793/examplemodule.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Example module with C-level module-global state, and
33
44
- a simple function that updates and queries the state
5-
- a class wihose repr() queries the same module state (for an example of
5+
- a class wihose repr() queries the same module state (as an example of
66
PyType_GetModuleByToken)
77
88
Once compiled and renamed to not include a version tag (for example
@@ -67,6 +67,7 @@ exampletype_repr(PyObject *self)
6767
return NULL;
6868
}
6969
examplemodule_state *state = PyModule_GetState(module);
70+
Py_DECREF(module);
7071
if (!state) {
7172
return NULL;
7273
}
@@ -95,8 +96,10 @@ examplemodule_exec(PyObject *module) {
9596
return -1;
9697
}
9798
if (PyModule_AddType(module, type) < 0) {
99+
Py_DECREF(type);
98100
return -1;
99101
}
102+
Py_DECREF(type);
100103
return 0;
101104
}
102105

0 commit comments

Comments
 (0)