Fixed all “definitely lost” ones from valgrind that originate in my code when 
using test86.in. Tested only with test86.in.

# HG changeset patch
# User ZyX <[email protected]>
# Date 1368989500 -14400
# Branch python-extended-2
# Node ID ae6c6a2f0d15539131afa603c873c35d8b673247
# Parent  bacfe074616e538efcea1f6841cc8a6f99ab20a5
Fix some memory leaks

diff -r bacfe074616e -r ae6c6a2f0d15 src/if_py_both.h
--- a/src/if_py_both.h  Sun May 19 23:43:10 2013 +0400
+++ b/src/if_py_both.h  Sun May 19 22:51:40 2013 +0400
@@ -866,6 +866,7 @@
     DICTKEY_UNREF
 
     copy_tv(&tv, &di->di_tv);
+    clear_tv(&tv);
     return 0;
 }
 
@@ -1129,6 +1130,7 @@
     {
        if (list_append_tv(l, &tv) == FAIL)
        {
+           clear_tv(&tv);
            PyErr_SetVim(_("Failed to add item to list"));
            return -1;
        }
@@ -1138,6 +1140,7 @@
        li = list_find(l, (long) index);
        clear_tv(&li->li_tv);
        copy_tv(&tv, &li->li_tv);
+       clear_tv(&tv);
     }
     return 0;
 }
@@ -1204,9 +1207,11 @@
            return -1;
        if (list_insert_tv(l, &v, li) == FAIL)
        {
+           clear_tv(&v);
            PyErr_SetVim(_("internal error: failed to add item to list"));
            return -1;
        }
+       clear_tv(&v);
     }
     return 0;
 }
@@ -1346,7 +1351,10 @@
                return NULL;
            }
            if (ConvertFromPyObject(selfdictObject, &selfdicttv) == -1)
+           {
+               clear_tv(&args);
                return NULL;
+           }
            selfdict = selfdicttv.vval.v_dict;
        }
     }
@@ -1370,13 +1378,10 @@
     else
        result = ConvertToPyObject(&rettv);
 
-    /* FIXME Check what should really be cleared. */
     clear_tv(&args);
     clear_tv(&rettv);
-    /*
-     * if (selfdict!=NULL)
-     *     clear_tv(selfdicttv);
-     */
+    if (selfdict != NULL)
+       clear_tv(&selfdicttv);
 
     return result;
 }
@@ -1482,7 +1487,7 @@
     }
     else if (flags & SOPT_BOOL)
     {
-       PyObject *r;
+       PyObject        *r;
        r = numval ? Py_True : Py_False;
        Py_INCREF(r);
        return r;
@@ -1492,7 +1497,11 @@
     else if (flags & SOPT_STRING)
     {
        if (stringval)
-           return PyBytes_FromString((char *) stringval);
+       {
+           PyObject    *r = PyBytes_FromString((char *) stringval);
+           vim_free(stringval);
+           return r;
+       }
        else
        {
            PyErr_SetString(PyExc_RuntimeError,
@@ -1516,9 +1525,9 @@
     int                opt_type;
     void       *from;
 {
-    win_T      *save_curwin;
-    tabpage_T  *save_curtab;
-    buf_T      *save_curbuf;
+    win_T      *save_curwin = NULL;
+    tabpage_T  *save_curtab = NULL;
+    buf_T      *save_curbuf = NULL;
     int                r = 0;
 
     VimTryStart();

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


*** /tmp/extdiff.T3qnx5/vim.bacfe074616e/src/if_py_both.h	2013-05-20 00:36:54.473349538 +0400
--- vim.ae6c6a2f0d15/src/if_py_both.h	2013-05-20 00:36:54.479349478 +0400
***************
*** 866,871 ****
--- 866,872 ----
      DICTKEY_UNREF
  
      copy_tv(&tv, &di->di_tv);
+     clear_tv(&tv);
      return 0;
  }
  
***************
*** 1129,1134 ****
--- 1130,1136 ----
      {
  	if (list_append_tv(l, &tv) == FAIL)
  	{
+ 	    clear_tv(&tv);
  	    PyErr_SetVim(_("Failed to add item to list"));
  	    return -1;
  	}
***************
*** 1138,1143 ****
--- 1140,1146 ----
  	li = list_find(l, (long) index);
  	clear_tv(&li->li_tv);
  	copy_tv(&tv, &li->li_tv);
+ 	clear_tv(&tv);
      }
      return 0;
  }
***************
*** 1204,1212 ****
--- 1207,1217 ----
  	    return -1;
  	if (list_insert_tv(l, &v, li) == FAIL)
  	{
+ 	    clear_tv(&v);
  	    PyErr_SetVim(_("internal error: failed to add item to list"));
  	    return -1;
  	}
+ 	clear_tv(&v);
      }
      return 0;
  }
***************
*** 1346,1352 ****
--- 1351,1360 ----
  		return NULL;
  	    }
  	    if (ConvertFromPyObject(selfdictObject, &selfdicttv) == -1)
+ 	    {
+ 		clear_tv(&args);
  		return NULL;
+ 	    }
  	    selfdict = selfdicttv.vval.v_dict;
  	}
      }
***************
*** 1370,1382 ****
      else
  	result = ConvertToPyObject(&rettv);
  
-     /* FIXME Check what should really be cleared. */
      clear_tv(&args);
      clear_tv(&rettv);
!     /*
!      * if (selfdict!=NULL)
!      *     clear_tv(selfdicttv);
!      */
  
      return result;
  }
--- 1378,1387 ----
      else
  	result = ConvertToPyObject(&rettv);
  
      clear_tv(&args);
      clear_tv(&rettv);
!     if (selfdict != NULL)
! 	clear_tv(&selfdicttv);
  
      return result;
  }
***************
*** 1482,1488 ****
      }
      else if (flags & SOPT_BOOL)
      {
! 	PyObject *r;
  	r = numval ? Py_True : Py_False;
  	Py_INCREF(r);
  	return r;
--- 1487,1493 ----
      }
      else if (flags & SOPT_BOOL)
      {
! 	PyObject	*r;
  	r = numval ? Py_True : Py_False;
  	Py_INCREF(r);
  	return r;
***************
*** 1492,1498 ****
      else if (flags & SOPT_STRING)
      {
  	if (stringval)
! 	    return PyBytes_FromString((char *) stringval);
  	else
  	{
  	    PyErr_SetString(PyExc_RuntimeError,
--- 1497,1507 ----
      else if (flags & SOPT_STRING)
      {
  	if (stringval)
! 	{
! 	    PyObject	*r = PyBytes_FromString((char *) stringval);
! 	    vim_free(stringval);
! 	    return r;
! 	}
  	else
  	{
  	    PyErr_SetString(PyExc_RuntimeError,
***************
*** 1516,1524 ****
      int		opt_type;
      void	*from;
  {
!     win_T	*save_curwin;
!     tabpage_T	*save_curtab;
!     buf_T	*save_curbuf;
      int		r = 0;
  
      VimTryStart();
--- 1525,1533 ----
      int		opt_type;
      void	*from;
  {
!     win_T	*save_curwin = NULL;
!     tabpage_T	*save_curtab = NULL;
!     buf_T	*save_curbuf = NULL;
      int		r = 0;
  
      VimTryStart();

Raspunde prin e-mail lui