From 7c2ea15ac3d884395e18eee5fd853e30f60eb80f Mon Sep 17 00:00:00 2001 From: "Luiz Fernando N. Capitulino" Date: Fri, 13 Jul 2007 20:01:49 -0300 Subject: [PATCH] libgit-thin: pygit: Memory leak fix Signed-off-by: Luiz Fernando N. Capitulino --- libgit-thin/pygit/pygit.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/libgit-thin/pygit/pygit.c b/libgit-thin/pygit/pygit.c index 32a1253567..3464b6a4cb 100644 --- a/libgit-thin/pygit/pygit.c +++ b/libgit-thin/pygit/pygit.c @@ -17,9 +17,12 @@ pygit_repo_read_commit(GitRepoObject *self, PyObject *args) { int err; void *buf; + PyObject *ret; const char *hex; unsigned char sha1[GIT_SHA1_SIZE]; + UNUSED(self); + if (!PyArg_ParseTuple(args, "s", &hex)) return NULL; @@ -31,14 +34,16 @@ pygit_repo_read_commit(GitRepoObject *self, PyObject *args) if (err) return PyErr_SetFromErrno(PyExc_ValueError); - /* FIXME: We're leaking the commit buffer */ - return PyString_FromString((char *) buf); + ret = PyString_FromString((char *) buf); + free(buf); + + return ret; } static PyMethodDef git_repo_methods[] = { {"read_commit", (PyCFunction) pygit_repo_read_commit, METH_VARARGS, NULL}, - {NULL} + {NULL, NULL, 0, NULL} }; static PyObject * @@ -136,7 +141,7 @@ static PyMethodDef pygit_methods[] = { PyMODINIT_FUNC initpygit(void) { - /* Patch object types */ + /* Patch object type */ Git_Repo_Type.ob_type = &PyType_Type; (void) Py_InitModule("pygit", pygit_methods); -- 2.11.4.GIT