X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/b8996c34869f8fbd6edf7556d7bef921e55962ba..47e39aa9787af784b651e6be2ed219d0d40234fb:/src/simix/ActorImpl.cpp diff --git a/src/simix/ActorImpl.cpp b/src/simix/ActorImpl.cpp index 29453b18e6..a55a783f3b 100644 --- a/src/simix/ActorImpl.cpp +++ b/src/simix/ActorImpl.cpp @@ -73,8 +73,10 @@ void SIMIX_process_cleanup(smx_actor_t process) SIMIX_process_on_exit_runall(process); /* Unregister from the kill timer if any */ - if (process->kill_timer != nullptr) + if (process->kill_timer != nullptr) { SIMIX_timer_remove(process->kill_timer); + process->kill_timer = nullptr; + } xbt_os_mutex_acquire(simix_global->mutex); @@ -677,10 +679,9 @@ void simcall_HANDLER_process_join(smx_simcall_t simcall, smx_actor_t process, do simcall->issuer->waiting_synchro = sync; } -static int SIMIX_process_join_finish(smx_process_exit_status_t status, void* synchro) +static int SIMIX_process_join_finish(smx_process_exit_status_t status, smx_actor_t process, smx_activity_t sleep_act) { - simgrid::kernel::activity::SleepImpl* sleep = static_cast(synchro); - + simgrid::kernel::activity::SleepImpl* sleep = static_cast(sleep_act.get()); if (sleep->surf_sleep) { sleep->surf_sleep->cancel(); @@ -700,7 +701,8 @@ static int SIMIX_process_join_finish(smx_process_exit_status_t status, void* syn sleep->surf_sleep->unref(); sleep->surf_sleep = nullptr; } - // intrusive_ptr_release(process); // FIXME: We are leaking here. See comment in SIMIX_process_join() + intrusive_ptr_release(process); + intrusive_ptr_release(sleep_act.get()); return 0; } @@ -708,18 +710,16 @@ smx_activity_t SIMIX_process_join(smx_actor_t issuer, smx_actor_t process, doubl { smx_activity_t res = issuer->sleep(timeout); intrusive_ptr_add_ref(res.get()); - /* We are leaking the process here, but if we don't take the ref, we get a "use after free". - * The correct solution would be to derivate the type SynchroSleep into a SynchroProcessJoin, - * but the code is not clean enough for now for this. - * The C API should first be properly replaced with the C++ one, which is a fair amount of work. - */ intrusive_ptr_add_ref(process); SIMIX_process_on_exit(process, [](void*, void* arg) { - return simgrid::simix::kernelImmediate( - [&] { return SIMIX_process_join_finish(SMX_EXIT_SUCCESS, arg); }); + auto argp = static_cast*>(arg); + int res = simgrid::simix::kernelImmediate( + [&] { return SIMIX_process_join_finish(SMX_EXIT_SUCCESS, argp->first, argp->second); }); + delete argp; + return res; }, - &*res); + new std::pair(process, res)); return res; }