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:
Marcelo Matus 2005-12-16 01:21:59 +00:00
commit ff633b0680
8 changed files with 40 additions and 10 deletions

View file

@ -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 { };

View file

@ -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();
}

View file

@ -117,6 +117,7 @@ void ll(long long ull) {}
%include cmalloc.i
%malloc(void);
%free(void);
#endif

View file

@ -2,6 +2,7 @@ from import_nomodule import *
f = create_Foo()
test1(f,42)
delete_Foo(f)
b = Bar()
test1(b,37)

View file

@ -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)

View file

@ -84,6 +84,10 @@
}
%}
%{
const int Hello::hello;
%}
// Functions with keywords
%warnfilter(-314);

View file

@ -95,3 +95,4 @@ if s.type != "void *":
free_void(v)

View file

@ -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;
}
};
%}