changeset 4587:63c9b681c3db v7.3.1041

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)
author Bram Moolenaar <bram@vim.org>
date Wed, 29 May 2013 21:37:35 +0200
parents 8a8ac6b05748
children 15cf120f2a68
files src/if_py_both.h src/version.c
diffstat 2 files changed, 29 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/if_py_both.h
+++ b/src/if_py_both.h
@@ -1603,11 +1603,10 @@ OptionsAssItem(OptionsObject *self, PyOb
     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 @@ OptionsAssItem(OptionsObject *self, PyOb
 	{
 	    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 @@ OptionsAssItem(OptionsObject *self, PyOb
 	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 @@ OptionsAssItem(OptionsObject *self, PyOb
 	else
 	{
 	    PyErr_SetString(PyExc_TypeError, _("object must be integer"));
+	    DICTKEY_UNREF
 	    return -1;
 	}
 
@@ -1670,9 +1674,15 @@ OptionsAssItem(OptionsObject *self, PyOb
 	{
 
 	    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 @@ OptionsAssItem(OptionsObject *self, PyOb
 
 	    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 @@ OptionsAssItem(OptionsObject *self, PyOb
 	else
 	{
 	    PyErr_SetString(PyExc_TypeError, _("object must be string"));
+	    DICTKEY_UNREF
 	    return -1;
 	}
 
@@ -1703,6 +1723,8 @@ OptionsAssItem(OptionsObject *self, PyOb
 	vim_free(val);
     }
 
+    DICTKEY_UNREF
+
     return r;
 }
 
--- a/src/version.c
+++ b/src/version.c
@@ -729,6 +729,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1041,
+/**/
     1040,
 /**/
     1039,