no.email at nospam.invalid
Mon Aug 30 08:07:03 CEST 2010
Lawrence D'Oliveiro <ldo at geek-central.gen.new_zealand> writes:
> static void GetBufferInfo
> ( ...
> do /*once*/
> TheBufferInfo = PyObject_CallMethod(FromArray, "buffer_info", "");
> if (TheBufferInfo == 0)
> AddrObj = PyTuple_GetItem(TheBufferInfo, 0);
> LenObj = PyTuple_GetItem(TheBufferInfo, 1);
> if (PyErr_Occurred())
> while (false);
> } /*GetBufferInfo*/
> It’s quite easy to assure yourself that this is never going to leak memory.
Actually that code looks suspicious. Suppose in
AddrObj = PyTuple_GetItem(TheBufferInfo, 0);
LenObj = PyTuple_GetItem(TheBufferInfo, 1);
the first PyTuple_GetItem succeeds and the second one fails. Then
AddrObj is a borrowed reference to the first tuple element and LenObj is
null, the error flag is set, so you break out of the do/while. You then
decrement the refcount of AddrObj even though you didn't increment it.
Maybe there's an explanation that makes it ok somehow, but it still
looks messy. This is the kind of problem I'm referring to in general.
More information about the Python-list