Check if model_simulation is NULL before delete - #14
Conversation
Set it to NULL after delete
|
Why do you delete the pointer before reallocating it ? If your code is exception-safe (it should!), then this should be unneeded. Invariants to enforce:
The best way to achieve that is to use a on-the-stack |
|
Ok, I'll try to use [Thread debugging using libthread_db enabled] |
remove delete pointer of configureHook and keep it only in cleanupHook
|
@doudou, does it seem better? |
| delete model_simulation; | ||
| model_simulation = new ModelSimulation(simulator, TaskContext::getPeriod(), _sim_per_cycle.get(), 0); | ||
| std::auto_ptr<ModelSimulation> sim(new ModelSimulation(simulator, TaskContext::getPeriod(), _sim_per_cycle.get(), 0)); | ||
| model_simulation = sim.release(); |
There was a problem hiding this comment.
Used like this, it makes no difference. If the constructor raises, then the object is never initialized. If the constructor passes, then you release it right away.
If you move the release just before the return true;, then things are becoming more interesting. If the parameters are invalid (in setUWParameters) and you raise, then you keep your invariants.
If you get a crash, run under valgrind. It should give you a better idea of what's going on.
There was a problem hiding this comment.
what was going on was that he was deleting the pointer twice (cleanupHook AND configureHook)
EDIT: because he was not setting it to NULL after deleting in the cleanupHook
There was a problem hiding this comment.
But .. the PR was adding the reinit to NULL. I'm confused. Anyways, glad I could help ;-)
There was a problem hiding this comment.
Thanks guy.
I tested it today and had no problem.
Merging it
Set it to NULL after delete