Josh Rosenberg <shadowranger+pyt...@gmail.com> added the comment:
You've got a reference leak in your __index__ based paths. PyNumber_Index is returning a new reference (either to the existing obj, or a new one, if the existing obj isn't already an int). You never release this reference. Simplest fix is to make intobj top level, initialized to NULL, and Py_XDECREF it along the convert_from_int code path (you can't DECREF it in the index specific path because it needs to survive past the goto, since it's replacing obj). I'm also mildly concerned by how duplicative the code becomes post-patch. If it's not a major performance hit (don't think it is; not even sure the API is even used anymore), perhaps just implement _PyTime_ObjectToTime_t as a wrapper for _PyTime_ObjectToDenominator (with a denominator of 2, so rounding simplifies to just 0 == round down, 1 == round up)? Example: int _PyTime_ObjectToTime_t(PyObject *obj, time_t *sec, _PyTime_round_t round) { long numerator; if (_PyTime_ObjectToDenominator(obj, sec, &numerator, 2, round) == 0) { if (numerator) { if (*sec == _Py_IntegralTypeMax(time_t)) { error_time_t_overflow(); return -1; } ++*sec; } return 0; } return -1; } Sorry for not commenting on GitHub, but my work computer has a broken Firefox that GitHub no longer supports properly. ---------- nosy: +josh.r _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue35707> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com