fix memory leaks
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7990 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
174c1f84a5
commit
ff633b0680
8 changed files with 40 additions and 10 deletions
|
|
@ -23,6 +23,10 @@ Foo *create_Foo() {
|
|||
return new Foo();
|
||||
}
|
||||
|
||||
void delete_Foo(Foo *f) {
|
||||
delete f;
|
||||
}
|
||||
|
||||
void test1(Foo *f, Integer x) { }
|
||||
|
||||
class Bar : public Foo { };
|
||||
|
|
|
|||
|
|
@ -40,6 +40,10 @@ Foo *new_Foo() {
|
|||
return new Foo();
|
||||
}
|
||||
|
||||
void delete_Foo(Foo *f) {
|
||||
return delete f;
|
||||
}
|
||||
|
||||
char *do_blah(Foo *f) {
|
||||
return f->blah();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,6 +117,7 @@ void ll(long long ull) {}
|
|||
|
||||
%include cmalloc.i
|
||||
%malloc(void);
|
||||
%free(void);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ from import_nomodule import *
|
|||
|
||||
f = create_Foo()
|
||||
test1(f,42)
|
||||
delete_Foo(f)
|
||||
|
||||
b = Bar()
|
||||
test1(b,37)
|
||||
|
|
|
|||
|
|
@ -15,3 +15,5 @@ if x != "Bar::blah":
|
|||
x = inherit_missing.do_blah(c)
|
||||
if x != "Spam::blah":
|
||||
print "Whoa! Bad return", x
|
||||
|
||||
inherit_missing.delete_Foo(a)
|
||||
|
|
|
|||
|
|
@ -84,6 +84,10 @@
|
|||
}
|
||||
|
||||
%}
|
||||
%{
|
||||
const int Hello::hello;
|
||||
%}
|
||||
|
||||
|
||||
// Functions with keywords
|
||||
%warnfilter(-314);
|
||||
|
|
|
|||
|
|
@ -95,3 +95,4 @@ if s.type != "void *":
|
|||
|
||||
|
||||
|
||||
free_void(v)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ It was reported in bug 899332 by Jermey Brown (jhbrown94) */
|
|||
|
||||
%module return_const_value
|
||||
|
||||
|
||||
%inline %{
|
||||
|
||||
class Foo {
|
||||
|
|
@ -16,17 +17,29 @@ public:
|
|||
|
||||
class Foo_ptr {
|
||||
Foo *_ptr;
|
||||
mutable bool _own;
|
||||
|
||||
public:
|
||||
Foo_ptr(Foo *p): _ptr(p) {}
|
||||
static Foo_ptr getPtr() {
|
||||
return Foo_ptr(new Foo(17));
|
||||
}
|
||||
static const Foo_ptr getConstPtr() {
|
||||
return Foo_ptr(new Foo(17));
|
||||
}
|
||||
const Foo *operator->() {
|
||||
return _ptr;
|
||||
}
|
||||
Foo_ptr(Foo *p, int own = false): _ptr(p), _own(own) {}
|
||||
static Foo_ptr getPtr() {
|
||||
return Foo_ptr(new Foo(17), true);
|
||||
}
|
||||
static const Foo_ptr getConstPtr() {
|
||||
return Foo_ptr(new Foo(17), true);
|
||||
}
|
||||
const Foo *operator->() {
|
||||
return _ptr;
|
||||
}
|
||||
|
||||
Foo_ptr(const Foo_ptr& f) : _ptr(f._ptr), _own(f._own)
|
||||
{
|
||||
f._own = 0;
|
||||
}
|
||||
|
||||
|
||||
~Foo_ptr() {
|
||||
if(_own) delete _ptr;
|
||||
}
|
||||
};
|
||||
|
||||
%}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue