Author josh.r
Recipients AVINASH MISHRA, jdemeyer, josh.r, ncoghlan, remi.lapeyre, ronaldoussoren, serhiy.storchaka, vstinner
Date 2019-01-28.16:53:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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)?


_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)) {
               return -1;
       return 0;
    return -1;

Sorry for not commenting on GitHub, but my work computer has a broken Firefox that GitHub no longer supports properly.
Date User Action Args
2019-01-28 16:53:13josh.rsetrecipients: + josh.r, ronaldoussoren, ncoghlan, vstinner, serhiy.storchaka, jdemeyer, remi.lapeyre, AVINASH MISHRA
2019-01-28 16:53:11josh.rsetmessageid: <>
2019-01-28 16:53:11josh.rlinkissue35707 messages
2019-01-28 16:53:11josh.rcreate