Navigation Menu

Skip to content

Commit

Permalink
Fixed major memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
alex committed Jun 13, 2009
1 parent 4a5ce0f commit be56701
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 29 deletions.
35 changes: 21 additions & 14 deletions abc.cpp
Expand Up @@ -631,10 +631,11 @@ ISWFObject* ABCVm::buildNamedClass(ISWFObject* base, const string& s)
//module.dump();
if(m->f)
{
arguments args;
args.args.push_back(new Null);
arguments* args=new arguments;
args->args.push_back(new Null);
Function::as_function FP=(Function::as_function)ex->getPointerToFunction(m->f);
FP(base,&args);
FP(base,args);
args->decRef();
}
return base;
}
Expand Down Expand Up @@ -775,24 +776,30 @@ void ABCVm::callPropVoid(method_info* th, int n, int m)
{
string name=th->vm->getMultinameString(n);
LOG(CALLS,"callPropVoid " << name << ' ' << m);
arguments args;
args.args.resize(m);
arguments* args=new arguments;
args->args.resize(m);
for(int i=0;i<m;i++)
args.args[m-i-1]=th->runtime_stack_pop();
args->args[m-i-1]=th->runtime_stack_pop();
ISWFObject* obj=th->runtime_stack_pop();
bool found;
ISWFObject* o=obj->getVariableByName(name,found);
//If o is already a function call it, otherwise find the Call method
if(o->getObjectType()==T_FUNCTION)
if(found)
{
IFunction* f=dynamic_cast<IFunction*>(o);
f->call(obj,&args);
//If o is already a function call it, otherwise find the Call method
if(o->getObjectType()==T_FUNCTION)
{
IFunction* f=dynamic_cast<IFunction*>(o);
f->call(obj,args);
}
else
{
IFunction* f=dynamic_cast<IFunction*>(o->getVariableByName(".Call",found));
f->call(obj,args);
}
}
else
{
IFunction* f=dynamic_cast<IFunction*>(o->getVariableByName(".Call",found));
f->call(obj,&args);
}
LOG(NOT_IMPLEMENTED,"Calling an undefined function");
args->decRef();
obj->decRef();
}

Expand Down
15 changes: 14 additions & 1 deletion asobjects.cpp
Expand Up @@ -162,7 +162,7 @@ ASFUNCTIONBODY(ASString,String)
{
Number* n=dynamic_cast<Number*>(args->args[0]);
ostringstream oss;
oss << setprecision(8) << fixed << n->val;
oss << setprecision(8) << fixed << *n;

th->data=oss.str();
return th;
Expand Down Expand Up @@ -390,6 +390,19 @@ void Number::copyFrom(const ISWFObject* o)
LOG(TRACE,"Set to " << n->val);
}

bool Number::isLess(const ISWFObject* o) const
{
if(o->getObjectType()==T_INTEGER)
{
const Integer* i=dynamic_cast<const Integer*>(o);
return val<*i;
}
else
{
return ISWFObject::isLess(o);
}
}

string Number::toString() const
{
char buf[20];
Expand Down
2 changes: 1 addition & 1 deletion asobjects.h
Expand Up @@ -128,7 +128,6 @@ class RunState

class Number : public ASObject
{
friend class ASString;
private:
double val;
public:
Expand All @@ -144,6 +143,7 @@ friend class ASString;
return new Number(*this);
}
void copyFrom(const ISWFObject* o);
bool isLess(const ISWFObject* o) const;
};

class ASMovieClip: public ASObject, public IRenderObject, public InteractiveObject
Expand Down
5 changes: 4 additions & 1 deletion swf.cpp
Expand Up @@ -587,15 +587,18 @@ void* RenderThread::sdl_worker(RenderThread* th)

sem_post(&th->end_render);
if(sys->shutdown)
{
delete[] buffer;
pthread_exit(0);
}
}
}
catch(const char* e)
{
LOG(ERROR, "Exception caught " << e);
delete[] buffer;
exit(-1);
}
delete[] buffer;
}

void RenderThread::draw(Frame* f)
Expand Down
15 changes: 14 additions & 1 deletion swftypes.cpp
Expand Up @@ -63,6 +63,7 @@ bool ISWFObject::isGreater(const ISWFObject* r) const
bool ISWFObject::isLess(const ISWFObject* r) const
{
LOG(NOT_IMPLEMENTED,"Less than comparison between type "<<getObjectType()<< " and type " << r->getObjectType());
abort();
return false;
}

Expand Down Expand Up @@ -142,7 +143,7 @@ ISWFObject* ISWFObject::getVariableByName(const string& name, bool& found)
else
{
found=false;
return new Undefined;
return NULL;
}
}

Expand Down Expand Up @@ -745,6 +746,18 @@ ISWFObject::ISWFObject():parent(NULL),max_slot_index(0),binded(false),ref_count(
{
}

ISWFObject::~ISWFObject()
{
if(ref_count>1)
{
LOG(ERROR,"Destroying a still referenced object");
abort();
}
map<string,ISWFObject*>::iterator it=Variables.begin();
for(it;it!=Variables.end();it++)
it->second->decRef();
}

ISWFObject* ISWFObject::getParent()
{
return parent;
Expand Down
13 changes: 2 additions & 11 deletions swftypes.h
Expand Up @@ -85,12 +85,6 @@ friend class ASString;
STRING(){};
STRING(const char* s):String(s)
{
/* do
{
String.push_back(*s);
s++;
}
while(*s!=0);*/
}
bool operator==(const STRING& s)
{
Expand All @@ -114,10 +108,6 @@ friend class ASString;
{
return !String.size();
}
/* operator const char*() const
{
return String.data();
}*/
operator const std::string&() const
{
return String;
Expand All @@ -141,6 +131,7 @@ class ISWFObject
bool binded;
int ref_count;
public:
virtual ~ISWFObject();
void incRef() {ref_count++;}
void decRef()
{
Expand Down Expand Up @@ -312,7 +303,7 @@ friend class Number;
std::string toString() const;
int toInt();
float toFloat();
operator int(){return val;}
operator int() const{return val;}
ISWFObject* clone()
{
return new Integer(*this);
Expand Down

0 comments on commit be56701

Please sign in to comment.