summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2010-08-25 14:29:59 +1000
committerAndrew Tridgell <tridge@samba.org>2010-08-25 23:05:05 +1000
commit634e06e465be7a8921cb95884ec427f48bf812da (patch)
treea7e4fac46b60b4ed47a5d0081cfbd5105273acff /lib
parent9218de4b740427a5f381be59ab00a21b0690fb9e (diff)
downloadsamba-634e06e465be7a8921cb95884ec427f48bf812da.tar.gz
samba-634e06e465be7a8921cb95884ec427f48bf812da.tar.bz2
samba-634e06e465be7a8921cb95884ec427f48bf812da.zip
pytalloc: fixed py_talloc_steal()
py_talloc_steal() was implemented as a macro which evaluated it's 2nd argument twice. It was often called via a macro with a 2nd argument that was a function call, for example an allocation in py_talloc_new(). This meant it allocated memory twice, and leaked one of them. This re-implements py_talloc_steal() as a function, so that it only does the allocation once.
Diffstat (limited to 'lib')
-rw-r--r--lib/talloc/pytalloc.c8
-rw-r--r--lib/talloc/pytalloc.h2
2 files changed, 9 insertions, 1 deletions
diff --git a/lib/talloc/pytalloc.c b/lib/talloc/pytalloc.c
index 4e0b2eca2b..92b7b94052 100644
--- a/lib/talloc/pytalloc.c
+++ b/lib/talloc/pytalloc.c
@@ -52,6 +52,14 @@ PyObject *py_talloc_steal_ex(PyTypeObject *py_type, TALLOC_CTX *mem_ctx,
return (PyObject *)ret;
}
+/**
+ * Import an existing talloc pointer into a Python object.
+ */
+PyObject *py_talloc_steal(PyTypeObject *py_type, void *ptr)
+{
+ return py_talloc_steal_ex(py_type, ptr, ptr);
+}
+
/**
* Import an existing talloc pointer into a Python object, leaving the
diff --git a/lib/talloc/pytalloc.h b/lib/talloc/pytalloc.h
index 9b6587261c..cdcc57bf85 100644
--- a/lib/talloc/pytalloc.h
+++ b/lib/talloc/pytalloc.h
@@ -43,8 +43,8 @@ void py_talloc_dealloc(PyObject* self);
#define py_talloc_get_mem_ctx(py_obj) ((py_talloc_Object *)py_obj)->talloc_ctx
PyObject *py_talloc_steal_ex(PyTypeObject *py_type, TALLOC_CTX *mem_ctx, void *ptr);
+PyObject *py_talloc_steal(PyTypeObject *py_type, void *ptr);
PyObject *py_talloc_reference_ex(PyTypeObject *py_type, TALLOC_CTX *mem_ctx, void *ptr);
-#define py_talloc_steal(py_type, talloc_ptr) py_talloc_steal_ex(py_type, talloc_ptr, talloc_ptr)
#define py_talloc_reference(py_type, talloc_ptr) py_talloc_reference_ex(py_type, talloc_ptr, talloc_ptr)
/* Sane default implementation of reprfunc. */