diff --git a/common/main/newmenu.h b/common/main/newmenu.h index 0441acae7..94cca9d8d 100644 --- a/common/main/newmenu.h +++ b/common/main/newmenu.h @@ -354,7 +354,7 @@ struct newmenu : newmenu_layout, window, mixin_trackable_window newmenu_layout(title, subtitle, filename, src, tiny_mode, tabs_flag, citem_init, draw_box), window(src, x, y, w, h) { } - int *rval = nullptr; // Pointer to return value (for polling newmenus) + std::shared_ptr rval; // Pointer to return value (for polling newmenus) virtual window_event_result event_handler(const d_event &) override; static int process_until_closed(newmenu *); }; diff --git a/similar/main/newmenu.cpp b/similar/main/newmenu.cpp index 80fd6105e..bd2e96194 100644 --- a/similar/main/newmenu.cpp +++ b/similar/main/newmenu.cpp @@ -534,8 +534,8 @@ int newmenu_do2(const menu_title title, const menu_subtitle subtitle, const rang int newmenu::process_until_closed(newmenu *const menu) { - int rval = -1; - menu->rval = &rval; + auto rval = std::make_shared(-1); + menu->rval = rval; // Track to see when the window is freed // Doing this way in case another window is opened on top without its own polling loop // newmenu_do2 and simpler get their own event loop @@ -546,7 +546,7 @@ int newmenu::process_until_closed(newmenu *const menu) /* menu is now a pointer to freed memory, and cannot be accessed * further */ - return rval; + return *rval; } namespace {