adafruit / Adafruit_DotStar_Pi

DotStar module for Python on Raspberry Pi
GNU General Public License v3.0
60 stars 30 forks source link

Memory leak in getPixelColor? #15

Closed casoich closed 6 years ago

casoich commented 7 years ago
casoich commented 7 years ago

I now believe the leak to be in the .Color method (line 525 in the dotstar.c library) here:

// Given separate R, G, B, return a packed 32-bit color.
// Meh, mostly here for parity w/Arduino library.
static PyObject *Color(DotStarObject *self, PyObject *arg) {
    uint8_t   r, g, b;
    PyObject *result;

    if(!PyArg_ParseTuple(arg, "bbb", &r, &g, &b)) return NULL;

    result = Py_BuildValue("I", (r << 16) | (g << 8) | b);
    Py_INCREF(result);
    return result;
}

I don't know enough about C to know what's leaking, but I have an equivalent method in python, that does not leak:

def RGBto32(rIn,gIn,bIn):
    pass
    return ( ( rIn << 16 ) | ( gIn << 8 ) | bIn )

(note the pass is in there just to allow me to collapse the function in Sublime Text. :-) )

PaintYourDragon commented 6 years ago

Yep, that seemed to fix it. Thanks for spotting!