aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2010-08-19 16:34:52 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2010-08-19 17:33:28 -0300
commit57d17c090802a93aeffc3e85730a950edfd6f448 (patch)
tree69efd099e71b7bc9dc34dfff3ee9bf58a6986a9f /tests
parentf33d2585d59405e47a0b0592b7888caaa87d467f (diff)
Fix mem leak in shiboken tests.
Reviewer: Luciano Wolf <luciano.wolf@openbossa.org> Renato Ara├║jo <renato.filho@openbossa.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/samplebinding/typesystem_sample.xml21
1 files changed, 16 insertions, 5 deletions
diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml
index f23320cc..ec5f150d 100644
--- a/tests/samplebinding/typesystem_sample.xml
+++ b/tests/samplebinding/typesystem_sample.xml
@@ -744,6 +744,19 @@
</modify-function>
+ <inject-code class="native" position="beginning">
+ // simple class to avoid mem leak inside conversion rule used in arrayMethod
+ template&lt;typename T>
+ struct ArrayDeleter {
+ ArrayDeleter(T* ptr) : m_ptr(ptr) {}
+ ~ArrayDeleter() { delete[] m_ptr; }
+ operator T*() { return m_ptr; }
+ private:
+ T* m_ptr;
+ ArrayDeleter(const ArrayDeleter&amp;);
+ ArrayDeleter&amp; operator=(ArrayDeleter&amp;);
+ };
+ </inject-code>
<modify-function signature="arrayMethod(int, int*) const">
<modify-argument index="1">
<remove-argument/>
@@ -757,17 +770,15 @@
<conversion-rule class="native">
int numItems = PySequence_Size(%PYARG_1);
- int *%out = new int[numItems]; //memory leak
- for (int i=0; i &lt; numItems; i++) {
+ ArrayDeleter&lt;int> %out(new int[numItems]);
+ for (int i=0; i &lt; numItems; i++)
%out[i] = %CONVERTTOCPP[int](PySequence_GetItem(%PYARG_1, i));
- }
</conversion-rule>
<conversion-rule class="target">
PyObject *%out = PyList_New(count);
- for (int i=0; i &lt; count; i++) {
+ for (int i=0; i &lt; count; i++)
PyList_SET_ITEM(%out, i, %CONVERTTOPYTHON[int](%in[i]));
- }
</conversion-rule>
</modify-argument>