Skip to content
Snippets Groups Projects
Commit 581111a2 authored by Marius Bozga's avatar Marius Bozga
Browse files

fix memory leaks for labels in observers

parent 923b1300
No related branches found
No related tags found
No related merge requests found
......@@ -60,10 +60,16 @@ IfObserverInstance::IfObserverInstance(const IfObserverInstance& instance)
void IfObserverInstance::copy(const IfInstance* inst) {
IfObserverInstance* obs = (IfObserverInstance*)inst;
m_curLabel = obs->m_curLabel;
m_bCut = obs->m_bCut;
}
void IfObserverInstance::clearEventAt(const int i) {
// m_curLabel = m_curLabel->copy();
// m_curLabel->setAt(i, IfEvent::NIL);
IfLabel l(*m_curLabel);
l.setAt(i, IfEvent::NIL);
m_curLabel = l.store();
}
unsigned IfObserverInstance::if_pid_obs_queue_length(const if_pid_type pid) const {
......@@ -83,7 +89,7 @@ int IfObserverInstance::trace(const IfEvent* event) {
l->setAt(len, event);
l->setAt(len+1, NULL);
m_curLabel = l->store();
delete l;
return 1;
}
......@@ -187,8 +193,7 @@ IfMessage* IfObserverInstance::if_obs_input_ext(unsigned sid, if_pid_type* pid)
if ( evt->getKind() == IfEvent::INPUT &&
(sid == (unsigned)-1 || ((IfMessage*)evt->getAuxObj())->getSid() == sid ) ) {
m_curLabel = m_curLabel->copy();
m_curLabel->setAt(i, IfEvent::NIL);
clearEventAt(i);
if(pid != NULL) *pid = evt->getAuxPid();
return (IfMessage*)evt->getAuxObj();
}
......@@ -217,8 +222,7 @@ IfMessage* IfObserverInstance::if_obs_discard_ext(unsigned sid, if_pid_type* pid
if ( evt->getKind() == IfEvent::DISCARD &&
(sid == (unsigned)-1 || ((IfMessage*)evt->getAuxObj())->getSid() == sid ) ) {
m_curLabel = m_curLabel->copy();
m_curLabel->setAt(i, IfEvent::NIL);
clearEventAt(i);
if(pid != NULL) *pid = evt->getAuxPid();
return (IfMessage*)evt->getAuxObj();
}
......@@ -251,8 +255,7 @@ IfMessage* IfObserverInstance::if_obs_output_ext(unsigned sid, unsigned index,
if ( evt->getKind() == IfEvent::OUTPUT &&
(sid == (unsigned)-1 || ((IfMessage*)evt->getAuxObj())->getSid() == sid ) &&
!(index--) ) {
m_curLabel = m_curLabel->copy();
m_curLabel->setAt(i, IfEvent::NIL);
clearEventAt(i);
if(from != NULL) *from = evt->getPid();
if(via != NULL) *via = evt->getAuxPid();
if(to != NULL) {
......@@ -287,8 +290,7 @@ void IfObserverInstance::if_obs_fork_ext(unsigned process, if_pid_type* var, if_
if ( evt->getKind() == IfEvent::FORK &&
( process == (unsigned)-1 || process == if_pid_proc(evt->getAuxPid()) ) ) {
m_curLabel = m_curLabel->copy();
m_curLabel->setAt(i, IfEvent::NIL);
clearEventAt(i);
if(var != NULL) *var = evt->getAuxPid();
if(in != NULL) *in = evt->getPid();
return ;
......@@ -321,8 +323,7 @@ void IfObserverInstance::if_obs_kill_ext(unsigned process, if_pid_type* var, if_
if ( evt->getKind() == IfEvent::KILL &&
( process == (unsigned)-1 || if_pid_proc( evt->getAuxPid() ) == process ) ) {
m_curLabel = m_curLabel->copy();
m_curLabel->setAt(i, IfEvent::NIL);
clearEventAt(i);
if(var != NULL) *var = evt->getAuxPid();
if(in != NULL) *in = evt->getPid();
return ;
......@@ -353,8 +354,7 @@ IfMessage* IfObserverInstance::if_obs_deliver_ext(unsigned sid, if_pid_type* fro
if ( evt->getKind() == IfEvent::DELIVER &&
(sid == (unsigned)-1 || ((IfMessage*)evt->getAuxObj())->getSid() == sid ) ) {
m_curLabel = m_curLabel->copy();
m_curLabel->setAt(i, IfEvent::NIL);
clearEventAt(i);
if(from != NULL) *from = evt->getPid();
return (IfMessage*)evt->getAuxObj();
}
......@@ -383,8 +383,7 @@ void IfObserverInstance::if_obs_informal_ext(char* name, if_pid_type* in)
if ( evt->getKind() == IfEvent::INFORMAL &&
( name == NULL || !strcmp(name,(char*)evt->getAuxObj()) ) ) {
m_curLabel = m_curLabel->copy();
m_curLabel->setAt(i, IfEvent::NIL);
clearEventAt(i);
if(in != NULL) *in = evt->getPid();
return;
}
......@@ -409,8 +408,7 @@ if_real_type IfObserverInstance::if_obs_probability_ext()
IfEvent* evt = m_curLabel->getAt(i);
if ( evt->getKind() == IfEvent::PROBABILITY ) {
m_curLabel = m_curLabel->copy();
m_curLabel->setAt(i, IfEvent::NIL);
clearEventAt(i);
return evt->getAuxProbability();
}
}
......
......@@ -64,10 +64,12 @@ class IfObserverInstance : public IfInstance {
DECLARE_STORABLE(IfInstance)
protected:
void clearEventAt(const int);
unsigned if_pid_obs_queue_length(const if_pid_type pid) const;
protected:
IfLabel* m_curLabel;
public:
int trace(const IfEvent* event);
void flushLabel();
......@@ -97,6 +99,8 @@ class IfObserverInstance : public IfInstance {
if_boolean_type if_obs_probability();
if_real_type if_obs_probability_ext();
public:
long unsigned m_bCut;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment