Karsten Hopp 8c0a7c
To: vim_dev@googlegroups.com
Karsten Hopp 8c0a7c
Subject: Patch 7.3.1051
Karsten Hopp 8c0a7c
Fcc: outbox
Karsten Hopp 8c0a7c
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 8c0a7c
Mime-Version: 1.0
Karsten Hopp 8c0a7c
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 8c0a7c
Content-Transfer-Encoding: 8bit
Karsten Hopp 8c0a7c
------------
Karsten Hopp 8c0a7c
Karsten Hopp 8c0a7c
Patch 7.3.1051
Karsten Hopp 8c0a7c
Problem:    Python: possible memory leaks.
Karsten Hopp 8c0a7c
Solution:   Python patch 12: fix the leaks (ZyX)
Karsten Hopp 8c0a7c
Files:	    src/if_py_both.h
Karsten Hopp 8c0a7c
Karsten Hopp 8c0a7c
Karsten Hopp 8c0a7c
*** ../vim-7.3.1050/src/if_py_both.h	2013-05-29 22:46:22.000000000 +0200
Karsten Hopp 8c0a7c
--- src/if_py_both.h	2013-05-29 22:48:45.000000000 +0200
Karsten Hopp 8c0a7c
***************
Karsten Hopp 8c0a7c
*** 32,40 ****
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
  #define DICTKEY_DECL \
Karsten Hopp 8c0a7c
      PyObject	*dictkey_todecref;
Karsten Hopp 8c0a7c
! #define DICTKEY_GET(err) \
Karsten Hopp 8c0a7c
      if (!(key = StringToChars(keyObject, &dictkey_todecref))) \
Karsten Hopp 8c0a7c
  	return err; \
Karsten Hopp 8c0a7c
      if (*key == NUL) \
Karsten Hopp 8c0a7c
      { \
Karsten Hopp 8c0a7c
  	PyErr_SetString(PyExc_ValueError, _("empty keys are not allowed")); \
Karsten Hopp 8c0a7c
--- 32,48 ----
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
  #define DICTKEY_DECL \
Karsten Hopp 8c0a7c
      PyObject	*dictkey_todecref;
Karsten Hopp 8c0a7c
! #define DICTKEY_GET(err, decref) \
Karsten Hopp 8c0a7c
      if (!(key = StringToChars(keyObject, &dictkey_todecref))) \
Karsten Hopp 8c0a7c
+     { \
Karsten Hopp 8c0a7c
+ 	if (decref) \
Karsten Hopp 8c0a7c
+ 	{ \
Karsten Hopp 8c0a7c
+ 	    Py_DECREF(keyObject); \
Karsten Hopp 8c0a7c
+ 	} \
Karsten Hopp 8c0a7c
  	return err; \
Karsten Hopp 8c0a7c
+     } \
Karsten Hopp 8c0a7c
+     if (decref && !dictkey_todecref) \
Karsten Hopp 8c0a7c
+ 	dictkey_todecref = keyObject; \
Karsten Hopp 8c0a7c
      if (*key == NUL) \
Karsten Hopp 8c0a7c
      { \
Karsten Hopp 8c0a7c
  	PyErr_SetString(PyExc_ValueError, _("empty keys are not allowed")); \
Karsten Hopp 8c0a7c
***************
Karsten Hopp 8c0a7c
*** 602,608 ****
Karsten Hopp 8c0a7c
  		    Py_DECREF(newObj);
Karsten Hopp 8c0a7c
  		    return NULL;
Karsten Hopp 8c0a7c
  		}
Karsten Hopp 8c0a7c
- 		Py_DECREF(newObj);
Karsten Hopp 8c0a7c
  	    }
Karsten Hopp 8c0a7c
  	}
Karsten Hopp 8c0a7c
      }
Karsten Hopp 8c0a7c
--- 610,615 ----
Karsten Hopp 8c0a7c
***************
Karsten Hopp 8c0a7c
*** 947,953 ****
Karsten Hopp 8c0a7c
      dictitem_T	*di;
Karsten Hopp 8c0a7c
      DICTKEY_DECL
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
!     DICTKEY_GET(NULL)
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
      di = dict_find(self->dict, key, -1);
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
--- 954,960 ----
Karsten Hopp 8c0a7c
      dictitem_T	*di;
Karsten Hopp 8c0a7c
      DICTKEY_DECL
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
!     DICTKEY_GET(NULL, 0)
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
      di = dict_find(self->dict, key, -1);
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
***************
Karsten Hopp 8c0a7c
*** 977,983 ****
Karsten Hopp 8c0a7c
  	return -1;
Karsten Hopp 8c0a7c
      }
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
!     DICTKEY_GET(-1)
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
      di = dict_find(dict, key, -1);
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
--- 984,990 ----
Karsten Hopp 8c0a7c
  	return -1;
Karsten Hopp 8c0a7c
      }
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
!     DICTKEY_GET(-1, 0)
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
      di = dict_find(dict, key, -1);
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
***************
Karsten Hopp 8c0a7c
*** 1650,1656 ****
Karsten Hopp 8c0a7c
      if (self->Check(self->from))
Karsten Hopp 8c0a7c
  	return NULL;
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
!     DICTKEY_GET(NULL)
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
      flags = get_option_value_strict(key, &numval, &stringval,
Karsten Hopp 8c0a7c
  				    self->opt_type, self->from);
Karsten Hopp 8c0a7c
--- 1657,1663 ----
Karsten Hopp 8c0a7c
      if (self->Check(self->from))
Karsten Hopp 8c0a7c
  	return NULL;
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
!     DICTKEY_GET(NULL, 0)
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
      flags = get_option_value_strict(key, &numval, &stringval,
Karsten Hopp 8c0a7c
  				    self->opt_type, self->from);
Karsten Hopp 8c0a7c
***************
Karsten Hopp 8c0a7c
*** 1789,1795 ****
Karsten Hopp 8c0a7c
      if (self->Check(self->from))
Karsten Hopp 8c0a7c
  	return -1;
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
!     DICTKEY_GET(-1)
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
      flags = get_option_value_strict(key, NULL, NULL,
Karsten Hopp 8c0a7c
  				    self->opt_type, self->from);
Karsten Hopp 8c0a7c
--- 1796,1802 ----
Karsten Hopp 8c0a7c
      if (self->Check(self->from))
Karsten Hopp 8c0a7c
  	return -1;
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
!     DICTKEY_GET(-1, 0)
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
      flags = get_option_value_strict(key, NULL, NULL,
Karsten Hopp 8c0a7c
  				    self->opt_type, self->from);
Karsten Hopp 8c0a7c
***************
Karsten Hopp 8c0a7c
*** 4029,4040 ****
Karsten Hopp 8c0a7c
      {
Karsten Hopp 8c0a7c
  	DICTKEY_DECL
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
! 	if (keyObject == NULL)
Karsten Hopp 8c0a7c
! 	    return -1;
Karsten Hopp 8c0a7c
! 	if (valObject == NULL)
Karsten Hopp 8c0a7c
  	    return -1;
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
! 	DICTKEY_GET(-1)
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
  	di = dictitem_alloc(key);
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
--- 4036,4045 ----
Karsten Hopp 8c0a7c
      {
Karsten Hopp 8c0a7c
  	DICTKEY_DECL
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
! 	if (keyObject == NULL || valObject == NULL)
Karsten Hopp 8c0a7c
  	    return -1;
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
! 	DICTKEY_GET(-1, 0)
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
  	di = dictitem_alloc(key);
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
***************
Karsten Hopp 8c0a7c
*** 4055,4060 ****
Karsten Hopp 8c0a7c
--- 4060,4066 ----
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
  	if (dict_add(dict, di) == FAIL)
Karsten Hopp 8c0a7c
  	{
Karsten Hopp 8c0a7c
+ 	    clear_tv(&di->di_tv);
Karsten Hopp 8c0a7c
  	    vim_free(di);
Karsten Hopp 8c0a7c
  	    PyErr_SetVim(_("failed to add key to dictionary"));
Karsten Hopp 8c0a7c
  	    return -1;
Karsten Hopp 8c0a7c
***************
Karsten Hopp 8c0a7c
*** 4100,4123 ****
Karsten Hopp 8c0a7c
  	    return -1;
Karsten Hopp 8c0a7c
  	}
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
! 	keyObject = PyTuple_GetItem(litem, 0);
Karsten Hopp 8c0a7c
! 	if (keyObject == NULL)
Karsten Hopp 8c0a7c
  	{
Karsten Hopp 8c0a7c
  	    Py_DECREF(list);
Karsten Hopp 8c0a7c
  	    Py_DECREF(litem);
Karsten Hopp 8c0a7c
  	    return -1;
Karsten Hopp 8c0a7c
  	}
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
! 	DICTKEY_GET(-1)
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
! 	valObject = PyTuple_GetItem(litem, 1);
Karsten Hopp 8c0a7c
! 	if (valObject == NULL)
Karsten Hopp 8c0a7c
  	{
Karsten Hopp 8c0a7c
  	    Py_DECREF(list);
Karsten Hopp 8c0a7c
  	    Py_DECREF(litem);
Karsten Hopp 8c0a7c
  	    return -1;
Karsten Hopp 8c0a7c
  	}
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
  	di = dictitem_alloc(key);
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
  	DICTKEY_UNREF
Karsten Hopp 8c0a7c
--- 4106,4130 ----
Karsten Hopp 8c0a7c
  	    return -1;
Karsten Hopp 8c0a7c
  	}
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
! 	if (!(keyObject = PyTuple_GetItem(litem, 0)))
Karsten Hopp 8c0a7c
  	{
Karsten Hopp 8c0a7c
  	    Py_DECREF(list);
Karsten Hopp 8c0a7c
  	    Py_DECREF(litem);
Karsten Hopp 8c0a7c
  	    return -1;
Karsten Hopp 8c0a7c
  	}
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
! 	DICTKEY_GET(-1, 1)
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
! 	if (!(valObject = PyTuple_GetItem(litem, 1)))
Karsten Hopp 8c0a7c
  	{
Karsten Hopp 8c0a7c
  	    Py_DECREF(list);
Karsten Hopp 8c0a7c
  	    Py_DECREF(litem);
Karsten Hopp 8c0a7c
+ 	    DICTKEY_UNREF
Karsten Hopp 8c0a7c
  	    return -1;
Karsten Hopp 8c0a7c
  	}
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
+ 	Py_DECREF(litem);
Karsten Hopp 8c0a7c
+ 
Karsten Hopp 8c0a7c
  	di = dictitem_alloc(key);
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
  	DICTKEY_UNREF
Karsten Hopp 8c0a7c
***************
Karsten Hopp 8c0a7c
*** 4125,4131 ****
Karsten Hopp 8c0a7c
  	if (di == NULL)
Karsten Hopp 8c0a7c
  	{
Karsten Hopp 8c0a7c
  	    Py_DECREF(list);
Karsten Hopp 8c0a7c
! 	    Py_DECREF(litem);
Karsten Hopp 8c0a7c
  	    PyErr_NoMemory();
Karsten Hopp 8c0a7c
  	    return -1;
Karsten Hopp 8c0a7c
  	}
Karsten Hopp 8c0a7c
--- 4132,4138 ----
Karsten Hopp 8c0a7c
  	if (di == NULL)
Karsten Hopp 8c0a7c
  	{
Karsten Hopp 8c0a7c
  	    Py_DECREF(list);
Karsten Hopp 8c0a7c
! 	    Py_DECREF(valObject);
Karsten Hopp 8c0a7c
  	    PyErr_NoMemory();
Karsten Hopp 8c0a7c
  	    return -1;
Karsten Hopp 8c0a7c
  	}
Karsten Hopp 8c0a7c
***************
Karsten Hopp 8c0a7c
*** 4135,4152 ****
Karsten Hopp 8c0a7c
  	{
Karsten Hopp 8c0a7c
  	    vim_free(di);
Karsten Hopp 8c0a7c
  	    Py_DECREF(list);
Karsten Hopp 8c0a7c
! 	    Py_DECREF(litem);
Karsten Hopp 8c0a7c
  	    return -1;
Karsten Hopp 8c0a7c
  	}
Karsten Hopp 8c0a7c
  	if (dict_add(dict, di) == FAIL)
Karsten Hopp 8c0a7c
  	{
Karsten Hopp 8c0a7c
  	    vim_free(di);
Karsten Hopp 8c0a7c
  	    Py_DECREF(list);
Karsten Hopp 8c0a7c
- 	    Py_DECREF(litem);
Karsten Hopp 8c0a7c
  	    PyErr_SetVim(_("failed to add key to dictionary"));
Karsten Hopp 8c0a7c
  	    return -1;
Karsten Hopp 8c0a7c
  	}
Karsten Hopp 8c0a7c
- 	Py_DECREF(litem);
Karsten Hopp 8c0a7c
      }
Karsten Hopp 8c0a7c
      Py_DECREF(list);
Karsten Hopp 8c0a7c
      return 0;
Karsten Hopp 8c0a7c
--- 4142,4161 ----
Karsten Hopp 8c0a7c
  	{
Karsten Hopp 8c0a7c
  	    vim_free(di);
Karsten Hopp 8c0a7c
  	    Py_DECREF(list);
Karsten Hopp 8c0a7c
! 	    Py_DECREF(valObject);
Karsten Hopp 8c0a7c
  	    return -1;
Karsten Hopp 8c0a7c
  	}
Karsten Hopp 8c0a7c
+ 
Karsten Hopp 8c0a7c
+ 	Py_DECREF(valObject);
Karsten Hopp 8c0a7c
+ 
Karsten Hopp 8c0a7c
  	if (dict_add(dict, di) == FAIL)
Karsten Hopp 8c0a7c
  	{
Karsten Hopp 8c0a7c
+ 	    clear_tv(&di->di_tv);
Karsten Hopp 8c0a7c
  	    vim_free(di);
Karsten Hopp 8c0a7c
  	    Py_DECREF(list);
Karsten Hopp 8c0a7c
  	    PyErr_SetVim(_("failed to add key to dictionary"));
Karsten Hopp 8c0a7c
  	    return -1;
Karsten Hopp 8c0a7c
  	}
Karsten Hopp 8c0a7c
      }
Karsten Hopp 8c0a7c
      Py_DECREF(list);
Karsten Hopp 8c0a7c
      return 0;
Karsten Hopp 8c0a7c
***************
Karsten Hopp 8c0a7c
*** 4201,4213 ****
Karsten Hopp 8c0a7c
--- 4210,4227 ----
Karsten Hopp 8c0a7c
  	li = listitem_alloc();
Karsten Hopp 8c0a7c
  	if (li == NULL)
Karsten Hopp 8c0a7c
  	{
Karsten Hopp 8c0a7c
+ 	    Py_DECREF(iterator);
Karsten Hopp 8c0a7c
  	    PyErr_NoMemory();
Karsten Hopp 8c0a7c
  	    return -1;
Karsten Hopp 8c0a7c
  	}
Karsten Hopp 8c0a7c
  	li->li_tv.v_lock = 0;
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
  	if (_ConvertFromPyObject(item, &li->li_tv, lookup_dict) == -1)
Karsten Hopp 8c0a7c
+ 	{
Karsten Hopp 8c0a7c
+ 	    Py_DECREF(item);
Karsten Hopp 8c0a7c
+ 	    Py_DECREF(iterator);
Karsten Hopp 8c0a7c
  	    return -1;
Karsten Hopp 8c0a7c
+ 	}
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
  	list_append(l, li);
Karsten Hopp 8c0a7c
  
Karsten Hopp 8c0a7c
***************
Karsten Hopp 8c0a7c
*** 4241,4248 ****
Karsten Hopp 8c0a7c
  # else
Karsten Hopp 8c0a7c
  	capsule = PyCObject_FromVoidPtr(tv, NULL);
Karsten Hopp 8c0a7c
  # endif
Karsten Hopp 8c0a7c
! 	PyDict_SetItemString(lookup_dict, hexBuf, capsule);
Karsten Hopp 8c0a7c
! 	Py_DECREF(capsule);
Karsten Hopp 8c0a7c
  	if (py_to_tv(obj, tv, lookup_dict) == -1)
Karsten Hopp 8c0a7c
  	{
Karsten Hopp 8c0a7c
  	    tv->v_type = VAR_UNKNOWN;
Karsten Hopp 8c0a7c
--- 4255,4266 ----
Karsten Hopp 8c0a7c
  # else
Karsten Hopp 8c0a7c
  	capsule = PyCObject_FromVoidPtr(tv, NULL);
Karsten Hopp 8c0a7c
  # endif
Karsten Hopp 8c0a7c
! 	if (PyDict_SetItemString(lookup_dict, hexBuf, capsule))
Karsten Hopp 8c0a7c
! 	{
Karsten Hopp 8c0a7c
! 	    Py_DECREF(capsule);
Karsten Hopp 8c0a7c
! 	    tv->v_type = VAR_UNKNOWN;
Karsten Hopp 8c0a7c
! 	    return -1;
Karsten Hopp 8c0a7c
! 	}
Karsten Hopp 8c0a7c
  	if (py_to_tv(obj, tv, lookup_dict) == -1)
Karsten Hopp 8c0a7c
  	{
Karsten Hopp 8c0a7c
  	    tv->v_type = VAR_UNKNOWN;
Karsten Hopp 8c0a7c
*** ../vim-7.3.1050/src/version.c	2013-05-29 22:46:22.000000000 +0200
Karsten Hopp 8c0a7c
--- src/version.c	2013-05-29 22:48:31.000000000 +0200
Karsten Hopp 8c0a7c
***************
Karsten Hopp 8c0a7c
*** 730,731 ****
Karsten Hopp 8c0a7c
--- 730,733 ----
Karsten Hopp 8c0a7c
  {   /* Add new patch number below this line */
Karsten Hopp 8c0a7c
+ /**/
Karsten Hopp 8c0a7c
+     1051,
Karsten Hopp 8c0a7c
  /**/
Karsten Hopp 8c0a7c
Karsten Hopp 8c0a7c
-- 
Karsten Hopp 8c0a7c
hundred-and-one symptoms of being an internet addict:
Karsten Hopp 8c0a7c
25. You believe nothing looks sexier than a man in boxer shorts illuminated
Karsten Hopp 8c0a7c
    only by a 17" inch svga monitor.
Karsten Hopp 8c0a7c
Karsten Hopp 8c0a7c
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 8c0a7c
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 8c0a7c
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 8c0a7c
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///