Skip to content
Snippets Groups Projects
Commit 7657d38e authored by Jonathan Lambrechts's avatar Jonathan Lambrechts
Browse files

dg : remove major memory leaks

parent d01e2c85
No related branches found
No related tags found
No related merge requests found
......@@ -893,6 +893,17 @@ class constructorBindingT<tObj, t0, t1, t2, t3, void> : public luaMethodBinding
}
};
template <class t>
class destructorBindingT : public luaMethodBinding {
public:
int call(lua_State *L)
{
t *o = luaStack<t*>::get(L,1);
delete o;
return 0;
}
};
class classBinding {
std::string _className;
binding *_b;
......@@ -997,10 +1008,7 @@ class classBinding {
inline const std::string getDescription() const { return _description; }
inline classBinding *getParent() const { return _parent; }
std::map<std::string, luaMethodBinding *> methods;
template <typename cb>
methodBinding *addMethod(std::string n, cb f)
{
luaMethodBinding *mb = new methodBindingT<cb>(n, f);
void addMethodLua (std::string n, luaMethodBinding *mb) {
methods[n] = mb;
lua_State *L = _b->L;
lua_getglobal(L, _className.c_str());
......@@ -1013,6 +1021,12 @@ class classBinding {
lua_pushcclosure(L, callMethod, 1);
lua_setfield(L,methods, n.c_str()); //className.name = callMethod(mb)
lua_pop(L, 1);
}
template <typename cb>
methodBinding *addMethod(std::string n, cb f)
{
luaMethodBinding *mb = new methodBindingT<cb>(n, f);
addMethodLua(n,mb);
return mb;
}
template <typename tObj, typename t0, typename t1, typename t2, typename t3,
......@@ -1073,6 +1087,9 @@ classBinding *binding::addClass(std::string name)
{
className<t>::set(name);
classBinding *cb = new classBinding(this, name);
luaMethodBinding *d = new destructorBindingT<t>();
d->setDescription("destructor");
cb->addMethodLua("delete", d);
classes[name] = cb;
return cb;
}
......
......@@ -51,8 +51,7 @@ dataCacheDouble::dataCacheDouble(dataCacheMap *m, function *f):
m->addDataCacheDouble(this, f->isInvalitedOnElement());
_function = f;
for(int i=0; i<f->_childrenCache.size(); i++) {
dataCacheMap *m2 = m->newChild();
m->addSecondaryCache(m2);
m->addSecondaryCache(m->newChild());
}
_substitutions.resize(f->_substitutedFunctions.size());
for(int i=0; i<f->_substitutedFunctions.size(); i++) {
......@@ -522,5 +521,8 @@ functionReplaceCache::functionReplaceCache(dataCacheMap *m, functionReplace *rep
}
}
functionReplaceCache::~functionReplaceCache() {
for (int i = 0; i< map->_secondaryCaches.size(); i++) {
delete map->_secondaryCaches[i];
}
delete map;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment