Skip to content

Commit

Permalink
updated for version 7.3.1041
Browse files Browse the repository at this point in the history
Problem:    Python: Invalid read valgrind errors.
Solution:   Python patch 2: defer DICTKEY_UNREF until key is no longer needed.
            (ZyX)
  • Loading branch information
brammool committed May 29, 2013
1 parent 0014a53 commit 1bc2428
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
32 changes: 27 additions & 5 deletions src/if_py_both.h
Expand Up @@ -1603,11 +1603,10 @@ OptionsAssItem(OptionsObject *self, PyObject *keyObject, PyObject *valObject)
flags = get_option_value_strict(key, NULL, NULL,
self->opt_type, self->from);

DICTKEY_UNREF

if (flags == 0)
{
PyErr_SetObject(PyExc_KeyError, keyObject);
DICTKEY_UNREF
return -1;
}

Expand All @@ -1617,17 +1616,20 @@ OptionsAssItem(OptionsObject *self, PyObject *keyObject, PyObject *valObject)
{
PyErr_SetString(PyExc_ValueError,
_("unable to unset global option"));
DICTKEY_UNREF
return -1;
}
else if (!(flags & SOPT_GLOBAL))
{
PyErr_SetString(PyExc_ValueError, _("unable to unset option "
"without global value"));
DICTKEY_UNREF
return -1;
}
else
{
unset_global_local_option(key, self->from);
DICTKEY_UNREF
return 0;
}
}
Expand All @@ -1639,9 +1641,10 @@ OptionsAssItem(OptionsObject *self, PyObject *keyObject, PyObject *valObject)
int istrue = PyObject_IsTrue(valObject);

if (istrue == -1)
return -1;
r = set_option_value_for(key, istrue, NULL,
opt_flags, self->opt_type, self->from);
r = -1;
else
r = set_option_value_for(key, istrue, NULL,
opt_flags, self->opt_type, self->from);
}
else if (flags & SOPT_NUM)
{
Expand All @@ -1657,6 +1660,7 @@ OptionsAssItem(OptionsObject *self, PyObject *keyObject, PyObject *valObject)
else
{
PyErr_SetString(PyExc_TypeError, _("object must be integer"));
DICTKEY_UNREF
return -1;
}

Expand All @@ -1670,9 +1674,15 @@ OptionsAssItem(OptionsObject *self, PyObject *keyObject, PyObject *valObject)
{

if (PyString_AsStringAndSize(valObject, (char **) &val, NULL) == -1)
{
DICTKEY_UNREF
return -1;
}
if (val == NULL)
{
DICTKEY_UNREF
return -1;
}

val = vim_strsave(val);
}
Expand All @@ -1682,19 +1692,29 @@ OptionsAssItem(OptionsObject *self, PyObject *keyObject, PyObject *valObject)

bytes = PyUnicode_AsEncodedString(valObject, (char *)ENC_OPT, NULL);
if (bytes == NULL)
{
DICTKEY_UNREF
return -1;
}

if(PyString_AsStringAndSize(bytes, (char **) &val, NULL) == -1)
{
DICTKEY_UNREF
return -1;
}
if (val == NULL)
{
DICTKEY_UNREF
return -1;
}

val = vim_strsave(val);
Py_XDECREF(bytes);
}
else
{
PyErr_SetString(PyExc_TypeError, _("object must be string"));
DICTKEY_UNREF
return -1;
}

Expand All @@ -1703,6 +1723,8 @@ OptionsAssItem(OptionsObject *self, PyObject *keyObject, PyObject *valObject)
vim_free(val);
}

DICTKEY_UNREF

return r;
}

Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -728,6 +728,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1041,
/**/
1040,
/**/
Expand Down

0 comments on commit 1bc2428

Please sign in to comment.