updated for version 7.3.1041
Problem: Python: Invalid read valgrind errors.
Solution: Python patch 2: defer DICTKEY_UNREF until key is no longer needed.
(ZyX)
diff --git a/src/if_py_both.h b/src/if_py_both.h
index c02cce3..4fce4b8 100644
--- a/src/if_py_both.h
+++ b/src/if_py_both.h
@@ -1603,11 +1603,10 @@
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;
}
@@ -1617,17 +1616,20 @@
{
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;
}
}
@@ -1639,9 +1641,10 @@
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)
{
@@ -1657,6 +1660,7 @@
else
{
PyErr_SetString(PyExc_TypeError, _("object must be integer"));
+ DICTKEY_UNREF
return -1;
}
@@ -1670,9 +1674,15 @@
{
if (PyString_AsStringAndSize(valObject, (char **) &val, NULL) == -1)
+ {
+ DICTKEY_UNREF
return -1;
+ }
if (val == NULL)
+ {
+ DICTKEY_UNREF
return -1;
+ }
val = vim_strsave(val);
}
@@ -1682,12 +1692,21 @@
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);
@@ -1695,6 +1714,7 @@
else
{
PyErr_SetString(PyExc_TypeError, _("object must be string"));
+ DICTKEY_UNREF
return -1;
}
@@ -1703,6 +1723,8 @@
vim_free(val);
}
+ DICTKEY_UNREF
+
return r;
}