[Python-checkins] r60860 - python/trunk/Modules/_struct.c python/trunk/Modules/cStringIO.c
Neal Norwitz
nnorwitz at gmail.com
Sun Feb 24 09:39:37 CET 2008
Amaury,
Can you add test cases for both of these fixes?
Thanks,
n
--
On Sat, Feb 16, 2008 at 6:34 AM, amaury.forgeotdarc
<python-checkins at python.org> wrote:
> Author: amaury.forgeotdarc
> Date: Sat Feb 16 15:34:57 2008
> New Revision: 60860
>
> Modified:
> python/trunk/Modules/_struct.c
> python/trunk/Modules/cStringIO.c
> Log:
> Crashers of the day: Py_CLEAR must be used when there is a chance that the
> function can be called recursively.
> This was discussed in issue1020188.
>
> In python codebase, all occurrences of Py_[X]DECREF(xxx->yyy) are suspect,
> except when they appear in tp_new or tp_dealloc functions, or when
> the member cannot be of a user-defined class.
> Note that tp_init is not safe.
>
> I do have a (crashing) example for every changed line.
> Is it worth adding them to the test suite?
>
> Example:
>
> class SpecialStr(str):
> def __del__(self):
> s.close()
>
> import cStringIO
> s = cStringIO.StringIO(SpecialStr("text"))
> s.close() # Segfault
>
>
>
> Modified: python/trunk/Modules/_struct.c
> ==============================================================================
> --- python/trunk/Modules/_struct.c (original)
> +++ python/trunk/Modules/_struct.c Sat Feb 16 15:34:57 2008
> @@ -1471,7 +1471,7 @@
> return -1;
>
> Py_INCREF(o_format);
> - Py_XDECREF(soself->s_format);
> + Py_CLEAR(soself->s_format);
> soself->s_format = o_format;
>
> ret = prepare_s(soself);
>
> Modified: python/trunk/Modules/cStringIO.c
> ==============================================================================
> --- python/trunk/Modules/cStringIO.c (original)
> +++ python/trunk/Modules/cStringIO.c Sat Feb 16 15:34:57 2008
> @@ -575,8 +575,7 @@
>
> static PyObject *
> I_close(Iobject *self, PyObject *unused) {
> - Py_XDECREF(self->pbuf);
> - self->pbuf = NULL;
> + Py_CLEAR(self->pbuf);
> self->buf = NULL;
>
> self->pos = self->string_size = 0;
> _______________________________________________
> Python-checkins mailing list
> Python-checkins at python.org
> http://mail.python.org/mailman/listinfo/python-checkins
>
More information about the Python-checkins
mailing list