From 8b84f90a81ddb7c611f71ca35957ecc4bddb9747 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=2E=20David=20Ib=C3=A1=C3=B1ez?= <jdavid.ibp@gmail.com>
Date: Sun, 26 Feb 2012 19:57:33 +0100
Subject: [PATCH] (issue #56) Fix TreeBuilder deallocation

Also, add a comment to the TODO file about a memory management issue
found throught pygit2.
---
 TODO.txt | 4 ++++
 pygit2.c | 1 +
 2 files changed, 5 insertions(+)

diff --git a/TODO.txt b/TODO.txt
index a648a06..4a48a28 100644
--- a/TODO.txt
+++ b/TODO.txt
@@ -14,3 +14,7 @@ Other
 - Make the Py_LOCAL_INLINE macro to work with Python 2.6, 2.7 and 3.1
 - Use surrogateescape in Python 3, see PEP-383
 - Expose the ODB (Repository.odb)
+- According to Python documentation, tp_dealloc must call tp_free (instead of
+  PyObject_Del or similar) if the type is subclassable. So, go through the
+  code and switch to tp_free, or make the type not subclassable, on a case by
+  case basis.
diff --git a/pygit2.c b/pygit2.c
index e81c05e..7769ff4 100644
--- a/pygit2.c
+++ b/pygit2.c
@@ -1607,6 +1607,7 @@ static void
 TreeBuilder_dealloc(TreeBuilder* self)
 {
     git_treebuilder_free(self->bld);
+    PyObject_Del(self);
 }
 
 static PyObject *