Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dangling pointer #170

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions bandit/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ namespace bandit {
get_controller_address() = controller;
}

static void deregister_controller() {
get_controller_address() = nullptr;
}

static controller_t& registered_controller() {
auto controller = get_controller_address();
throw_if_nullptr(controller, "controller", "bandit::detail::register_controller()");
Expand Down Expand Up @@ -201,6 +205,10 @@ namespace bandit {
controller_t::register_controller(controller);
}

inline void deregister_controller() {
controller_t::deregister_controller();
}

inline controller_t& registered_controller() {
return controller_t::registered_controller();
}
Expand Down
5 changes: 4 additions & 1 deletion bandit/runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ namespace bandit {
controller.set_policy(new run_policy::bandit(opt.filter_chain(), opt.break_on_failure(), opt.dry_run()));

detail::register_controller(&controller);
return run(opt, detail::specs());
int result = run(opt, detail::specs());
detail::deregister_controller();

return result;
}

inline int run(int argc, char* argv[], bool allow_further = true) {
Expand Down