From 900be334dc2db54d0a934abe66e2fec86f592483 Mon Sep 17 00:00:00 2001 From: Jari Sundell Date: Sun, 16 Nov 2025 18:48:32 +0100 Subject: [PATCH] Cleaned up xmlrpc-c string sanitization. --- src/control.cc | 5 +-- src/display/canvas.cc | 68 +++++++++++++++++++++---------------- src/display/canvas.h | 63 ++++++++++++++++------------------ src/display/frame.cc | 63 ++++++++-------------------------- src/display/frame.h | 37 ++------------------ src/display/manager.h | 2 +- src/display/window.cc | 2 -- src/display/window.h | 2 +- src/display/window_input.cc | 34 ------------------- src/display/window_input.h | 34 ------------------- src/main.cc | 6 ++-- src/rpc/xmlrpc_c.cc | 16 ++++----- src/ui/download_list.cc | 8 ++--- src/ui/download_list.h | 34 ------------------- src/ui/root.cc | 23 ++++++++----- 15 files changed, 117 insertions(+), 280 deletions(-) diff --git a/src/control.cc b/src/control.cc index 731de960..fbfd057e 100644 --- a/src/control.cc +++ b/src/control.cc @@ -58,6 +58,8 @@ Control::~Control() { void Control::initialize() { + worker_thread->start_thread(); + display::Canvas::initialize(); display::Window::slot_schedule([this](display::Window* w, std::chrono::microseconds t) { m_display->schedule(w, t); }); display::Window::slot_unschedule([this](display::Window* w) { m_display->unschedule(w); }); @@ -81,9 +83,8 @@ Control::cleanup() { torrent::this_thread::scheduler()->erase(&m_task_shutdown); - if(!display::Canvas::daemon()) { + if(!display::Canvas::daemon()) m_inputStdin->remove(torrent::this_thread::poll()); - } m_core->download_store()->disable(); diff --git a/src/display/canvas.cc b/src/display/canvas.cc index 93f3e86d..23a4f5a5 100644 --- a/src/display/canvas.cc +++ b/src/display/canvas.cc @@ -11,23 +11,31 @@ namespace display { -bool Canvas::m_isInitialized = false; -bool Canvas::m_isDaemon = false; +bool Canvas::m_initialized{}; +bool Canvas::m_daemon{}; + // Maps ncurses color IDs to a ncurses attribute int std::unordered_map Canvas::m_attr_map = {}; Canvas::Canvas(int x, int y, int width, int height) { - if (!m_isDaemon) { + if (!m_daemon) { m_window = newwin(height, width, y, x); - if (m_window == NULL) + if (m_window == nullptr) throw torrent::internal_error("Could not allocate ncurses canvas."); } } +Canvas::~Canvas() { + if (!m_daemon && m_window != nullptr) { + delwin(m_window); + m_window = nullptr; + } +} + void Canvas::resize(int x, int y, int w, int h) { - if (!m_isDaemon) { + if (!m_daemon) { wresize(m_window, h, w); mvwin(m_window, y, x); } @@ -35,7 +43,7 @@ Canvas::resize(int x, int y, int w, int h) { void Canvas::print_attributes(unsigned int x, unsigned int y, const char* first, const char* last, const attributes_list* attributes) { - if (!m_isDaemon) { + if (!m_daemon) { move(x, y); attr_t org_attr; @@ -68,14 +76,13 @@ Canvas::print_attributes(unsigned int x, unsigned int y, const char* first, cons void Canvas::initialize() { - if (m_isInitialized) - return; + if (m_initialized) + throw torrent::internal_error("Canvas::initialize() called more than once."); - m_isDaemon = rpc::call_command_value("system.daemon"); + m_daemon = rpc::call_command_value("system.daemon"); + m_initialized = true; - m_isInitialized = true; - - if (!m_isDaemon) { + if (!m_daemon) { initscr(); start_color(); use_default_colors(); @@ -88,6 +95,19 @@ Canvas::initialize() { } } +void +Canvas::cleanup() { + if (!m_initialized) + return; + + m_initialized = false; + + if (!m_daemon) { + noraw(); + endwin(); + } +} + // Function wrapper for what possibly is a macro int get_colors() { @@ -102,7 +122,7 @@ Canvas::build_colors() { // This may get called early in the start process by the config // file, so we need to delay building until initscr() has a chance // to run - if (!m_isInitialized || m_isDaemon) + if (!m_initialized || m_daemon) return; // basic color names, index maps to ncurses COLOR_* @@ -115,7 +135,9 @@ Canvas::build_colors() { for (int k = 1; k < RCOLOR_MAX; k++) { init_pair(k, -1, -1); + std::string color_def = rpc::call_command_string(color_vars[k]); + if (color_def.empty()) continue; // Use terminal default if definition is empty @@ -126,6 +148,7 @@ Canvas::build_colors() { // Process string as space-separated words size_t start = 0, end = 0; + while (true) { end = color_def.find(' ', start); std::string word = color_def.substr(start, end - start); @@ -169,10 +192,8 @@ Canvas::build_colors() { // Check that fg & bg color index is valid if ((color[0] != -1 && color[0] >= get_colors()) || (color[1] != -1 && color[1] >= get_colors())) { - char buf[33]; - snprintf(buf, 33, "%d", get_colors()); Canvas::cleanup(); - throw torrent::input_error(color_def + ": your terminal only supports " + buf + " colors."); + throw torrent::input_error(color_def + ": your terminal only supports " + std::to_string(get_colors()) + " colors."); } m_attr_map[k] = attr; // overwrite or insert the value @@ -196,24 +217,11 @@ Canvas::build_colors() { } } -void -Canvas::cleanup() { - if (!m_isInitialized) - return; - - m_isInitialized = false; - - if (!m_isDaemon) { - noraw(); - endwin(); - } -} - std::pair Canvas::term_size() { struct winsize ws; - if (!m_isDaemon) { + if (!m_daemon) { if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == 0) return std::pair(ws.ws_col, ws.ws_row); } diff --git a/src/display/canvas.h b/src/display/canvas.h index dc5638cd..9203044e 100644 --- a/src/display/canvas.h +++ b/src/display/canvas.h @@ -54,9 +54,10 @@ public: // Initialize stdscr. static void initialize(); - static void build_colors(); static void cleanup(); + static void build_colors(); + static int get_screen_width(); static int get_screen_height(); @@ -64,15 +65,15 @@ public: static void do_update(); - static bool daemon() { return m_isDaemon; } + static bool daemon() { return m_daemon; } static const attributes_map& attr_map() { return m_attr_map; } private: Canvas(const Canvas&); void operator=(const Canvas&); - static bool m_isInitialized; - static bool m_isDaemon; + static bool m_initialized; + static bool m_daemon; // Maps ncurses color IDs to a ncurses attribute int static std::unordered_map m_attr_map; @@ -80,57 +81,51 @@ private: WINDOW* m_window; }; -inline Canvas::~Canvas() { - if (!m_isDaemon) { - delwin(m_window); - } -} - inline void Canvas::refresh() { - if (!m_isDaemon) { + if (!m_daemon) { wnoutrefresh(m_window); } } inline void Canvas::refresh_std() { - if (!m_isDaemon) { + if (!m_daemon) { wnoutrefresh(stdscr); } } inline void Canvas::redraw() { - if (!m_isDaemon) { + if (!m_daemon) { redrawwin(m_window); } } inline void Canvas::redraw_std() { - if (!m_isDaemon) { + if (!m_daemon) { redrawwin(stdscr); } } inline void Canvas::resize(int w, int h) { - if (!m_isDaemon) { + if (!m_daemon) { wresize(m_window, h, w); } } inline void Canvas::resize_term(int x, int y) { - if (!m_isDaemon) { + if (!m_daemon) { resizeterm(y, x); } } inline void Canvas::resize_term(std::pair dim) { - if (!m_isDaemon) { + if (!m_daemon) { resizeterm(dim.second, dim.first); } } @@ -139,7 +134,7 @@ inline unsigned int Canvas::get_x() { int x; [[maybe_unused]] int y; - if (!m_isDaemon) { + if (!m_daemon) { getyx(m_window, y, x); } else { x = 1; @@ -150,7 +145,7 @@ Canvas::get_x() { inline unsigned int Canvas::get_y() { int x, y; - if (!m_isDaemon) { + if (!m_daemon) { getyx(m_window, y, x); } else { y = 1; @@ -162,7 +157,7 @@ inline unsigned int Canvas::width() { int x; [[maybe_unused]] int y; - if (!m_isDaemon) { + if (!m_daemon) { getmaxyx(m_window, y, x); } else { x = 80; @@ -173,7 +168,7 @@ Canvas::width() { inline unsigned int Canvas::height() { int x, y; - if (!m_isDaemon) { + if (!m_daemon) { getmaxyx(m_window, y, x); } else { y = 24; @@ -183,21 +178,21 @@ Canvas::height() { inline void Canvas::move(unsigned int x, unsigned int y) { - if (!m_isDaemon) { + if (!m_daemon) { wmove(m_window, y, x); } } inline void Canvas::erase() { - if (!m_isDaemon) { + if (!m_daemon) { werase(m_window); } } inline void Canvas::erase_std() { - if (!m_isDaemon) { + if (!m_daemon) { werase(stdscr); } } @@ -206,7 +201,7 @@ inline void Canvas::print(const char* str, ...) { va_list arglist; - if (!m_isDaemon) { + if (!m_daemon) { va_start(arglist, str); vw_printw(m_window, const_cast(str), arglist); va_end(arglist); @@ -217,7 +212,7 @@ inline void Canvas::print(unsigned int x, unsigned int y, const char* str, ...) { va_list arglist; - if (!m_isDaemon) { + if (!m_daemon) { va_start(arglist, str); wmove(m_window, y, x); vw_printw(m_window, const_cast(str), arglist); @@ -227,35 +222,35 @@ Canvas::print(unsigned int x, unsigned int y, const char* str, ...) { inline void Canvas::print_char(const chtype ch) { - if (!m_isDaemon) { + if (!m_daemon) { waddch(m_window, ch); } } inline void Canvas::print_char(unsigned int x, unsigned int y, const chtype ch) { - if (!m_isDaemon) { + if (!m_daemon) { mvwaddch(m_window, y, x, ch); } } inline void Canvas::set_attr(unsigned int x, unsigned int y, unsigned int n, int attr, int color) { - if (!m_isDaemon) { + if (!m_daemon) { mvwchgat(m_window, y, x, n, attr, color, NULL); } } inline void Canvas::set_attr(unsigned int x, unsigned int y, unsigned int n, ColorKind k) { - if (!m_isDaemon) { + if (!m_daemon) { mvwchgat(m_window, y, x, n, m_attr_map[k], k, NULL); } } inline void Canvas::set_default_attributes(int attr) { - if (!m_isDaemon) { + if (!m_daemon) { (void)wattrset(m_window, attr); } } @@ -264,7 +259,7 @@ inline int Canvas::get_screen_width() { int x; [[maybe_unused]] int y; - if (!m_isDaemon) { + if (!m_daemon) { getmaxyx(stdscr, y, x); } else { x = 80; @@ -275,7 +270,7 @@ Canvas::get_screen_width() { inline int Canvas::get_screen_height() { int x, y; - if (!m_isDaemon) { + if (!m_daemon) { getmaxyx(stdscr, y, x); } else { y = 24; @@ -285,7 +280,7 @@ Canvas::get_screen_height() { inline void Canvas::do_update() { - if (!m_isDaemon) { + if (!m_daemon) { doupdate(); } } diff --git a/src/display/frame.cc b/src/display/frame.cc index 18b72668..1cad6b52 100644 --- a/src/display/frame.cc +++ b/src/display/frame.cc @@ -1,47 +1,12 @@ -// rTorrent - BitTorrent client -// Copyright (C) 2005-2011, Jari Sundell -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// In addition, as a special exception, the copyright holders give -// permission to link the code of portions of this program with the -// OpenSSL library under certain conditions as described in each -// individual source file, and distribute linked combinations -// including the two. -// -// You must obey the GNU General Public License in all respects for -// all of the code used other than OpenSSL. If you modify file(s) -// with this exception, you may extend this exception to your version -// of the file(s), but you are not obligated to do so. If you do not -// wish to do so, delete this exception statement from your version. -// If you delete this exception statement from all source files in the -// program, then also delete it here. -// -// Contact: Jari Sundell - - #include "config.h" +#include "display/frame.h" + #include #include - -#include #include -#include "frame.h" -#include "window.h" +#include "display/window.h" namespace display { @@ -137,7 +102,7 @@ Frame::preferred_size() const { for (size_type i = 0; i < m_containerSize; ++i) { bounds_type p = m_container[i]->preferred_size(); - + accum.minWidth += p.minWidth; accum.minHeight += p.minHeight; @@ -221,7 +186,7 @@ Frame::clear() { m_window->set_offscreen(true); break; - + case TYPE_ROW: case TYPE_COLUMN: for (size_type i = 0; i < m_containerSize; ++i) { @@ -335,10 +300,10 @@ Frame::balance_row(uint32_t x, uint32_t y, uint32_t width, uint32_t height) { dynamic_type dynamicFrames[max_size]; int remaining = height; - + for (Frame **itr = m_container, **last = m_container + m_containerSize; itr != last; ++itr) { bounds_type bounds = (*itr)->preferred_size(); - + if ((*itr)->is_height_dynamic()) { (*itr)->m_height = 0; dynamicFrames[dynamicSize++] = std::make_pair(*itr, bounds); @@ -367,11 +332,11 @@ Frame::balance_row(uint32_t x, uint32_t y, uint32_t width, uint32_t height) { for (dynamic_type *itr = dynamicFrames, *last = dynamicFrames + dynamicSize; itr != last; ++itr) { uint32_t adjust = (std::max(remaining, 0) + std::distance(itr, last) - 1) / std::distance(itr, last); - + adjust += itr->first->m_height; adjust = std::max(adjust, itr->second.minHeight); adjust = std::min(adjust, itr->second.maxHeight); - + remaining -= adjust - itr->first->m_height; retry = retry || itr->first->m_height != adjust; @@ -410,10 +375,10 @@ Frame::balance_column(uint32_t x, uint32_t y, uint32_t width, uint32_t height) { dynamic_type dynamicFrames[max_size]; int remaining = width; - + for (Frame **itr = m_container, **last = m_container + m_containerSize; itr != last; ++itr) { bounds_type bounds = (*itr)->preferred_size(); - + if ((*itr)->is_width_dynamic()) { (*itr)->m_width = 0; dynamicFrames[dynamicSize++] = std::make_pair(*itr, bounds); @@ -423,7 +388,7 @@ Frame::balance_column(uint32_t x, uint32_t y, uint32_t width, uint32_t height) { remaining -= bounds.minWidth; } } - + // Sort the dynamic frames by the min size in the direction we are // interested in. Then try to satisfy the largest first, and if we // have any remaining space we can use that to extend it and any @@ -442,11 +407,11 @@ Frame::balance_column(uint32_t x, uint32_t y, uint32_t width, uint32_t height) { for (dynamic_type *itr = dynamicFrames, *last = dynamicFrames + dynamicSize; itr != last; ++itr) { uint32_t adjust = (std::max(remaining, 0) + std::distance(itr, last) - 1) / std::distance(itr, last); - + adjust += itr->first->m_width; adjust = std::max(adjust, itr->second.minWidth); adjust = std::min(adjust, itr->second.maxWidth); - + remaining -= adjust - itr->first->m_width; retry = retry || itr->first->m_width != adjust; diff --git a/src/display/frame.h b/src/display/frame.h index 50cbd53e..b11cc906 100644 --- a/src/display/frame.h +++ b/src/display/frame.h @@ -1,41 +1,8 @@ -// rTorrent - BitTorrent client -// Copyright (C) 2005-2011, Jari Sundell -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// In addition, as a special exception, the copyright holders give -// permission to link the code of portions of this program with the -// OpenSSL library under certain conditions as described in each -// individual source file, and distribute linked combinations -// including the two. -// -// You must obey the GNU General Public License in all respects for -// all of the code used other than OpenSSL. If you modify file(s) -// with this exception, you may extend this exception to your version -// of the file(s), but you are not obligated to do so. If you do not -// wish to do so, delete this exception statement from your version. -// If you delete this exception statement from all source files in the -// program, then also delete it here. -// -// Contact: Jari Sundell - - #ifndef RTORRENT_DISPLAY_FRAME_H #define RTORRENT_DISPLAY_FRAME_H #include +#include namespace display { @@ -121,7 +88,7 @@ private: union { Window* m_window; - + struct { size_type m_containerSize; Frame* m_container[max_size]; diff --git a/src/display/manager.h b/src/display/manager.h index 403e14a0..32274a3c 100644 --- a/src/display/manager.h +++ b/src/display/manager.h @@ -3,7 +3,7 @@ #include -#include "frame.h" +#include "display/frame.h" namespace display { diff --git a/src/display/window.cc b/src/display/window.cc index 329c79d7..2a407558 100644 --- a/src/display/window.cc +++ b/src/display/window.cc @@ -31,8 +31,6 @@ Window::Window(Canvas* canvas, int flags, extent_type min_width, extent_type min Window::~Window() { if (is_active()) m_slot_unschedule(this); - - delete m_canvas; } void diff --git a/src/display/window.h b/src/display/window.h index c9540406..36b798ec 100644 --- a/src/display/window.h +++ b/src/display/window.h @@ -89,7 +89,7 @@ protected: static SlotWindow m_slot_unschedule; static Slot m_slot_adjust; - Canvas* m_canvas; + std::unique_ptr m_canvas; int m_flags; diff --git a/src/display/window_input.cc b/src/display/window_input.cc index b3870e17..1287f26f 100644 --- a/src/display/window_input.cc +++ b/src/display/window_input.cc @@ -1,37 +1,3 @@ -// rTorrent - BitTorrent client -// Copyright (C) 2005-2011, Jari Sundell -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// In addition, as a special exception, the copyright holders give -// permission to link the code of portions of this program with the -// OpenSSL library under certain conditions as described in each -// individual source file, and distribute linked combinations -// including the two. -// -// You must obey the GNU General Public License in all respects for -// all of the code used other than OpenSSL. If you modify file(s) -// with this exception, you may extend this exception to your version -// of the file(s), but you are not obligated to do so. If you do not -// wish to do so, delete this exception statement from your version. -// If you delete this exception statement from all source files in the -// program, then also delete it here. -// -// Contact: Jari Sundell - - #include "config.h" #include "canvas.h" diff --git a/src/display/window_input.h b/src/display/window_input.h index 721e91c1..aa8b6819 100644 --- a/src/display/window_input.h +++ b/src/display/window_input.h @@ -1,37 +1,3 @@ -// rTorrent - BitTorrent client -// Copyright (C) 2005-2011, Jari Sundell -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// In addition, as a special exception, the copyright holders give -// permission to link the code of portions of this program with the -// OpenSSL library under certain conditions as described in each -// individual source file, and distribute linked combinations -// including the two. -// -// You must obey the GNU General Public License in all respects for -// all of the code used other than OpenSSL. If you modify file(s) -// with this exception, you may extend this exception to your version -// of the file(s), but you are not obligated to do so. If you do not -// wish to do so, delete this exception statement from your version. -// If you delete this exception statement from all source files in the -// program, then also delete it here. -// -// Contact: Jari Sundell - - #ifndef RTORRENT_DISPLAY_WINDOW_INPUT_H #define RTORRENT_DISPLAY_WINDOW_INPUT_H diff --git a/src/main.cc b/src/main.cc index 1bff4faf..961f6d3e 100644 --- a/src/main.cc +++ b/src/main.cc @@ -215,6 +215,7 @@ main(int argc, char** argv) { torrent::initialize(); torrent::set_main_thread_slots(std::bind(&client_perform)); + // TODO: Move to controller. worker_thread = new ThreadWorker(); worker_thread->init_thread(); @@ -498,8 +499,6 @@ main(int argc, char** argv) { control->display()->adjust_layout(); control->display()->receive_update(); - worker_thread->start_thread(); - rpc::commands.call_catch("event.system.startup_done", rpc::make_target(), "startup_done", "System startup_done event action failed: "); torrent::utils::Thread::self()->event_loop(); @@ -534,7 +533,10 @@ main(int argc, char** argv) { torrent::log_cleanup(); delete control; + control = nullptr; + delete worker_thread; + worker_thread = nullptr; return 0; } diff --git a/src/rpc/xmlrpc_c.cc b/src/rpc/xmlrpc_c.cc index b1fccbb3..519c28ff 100644 --- a/src/rpc/xmlrpc_c.cc +++ b/src/rpc/xmlrpc_c.cc @@ -8,9 +8,9 @@ #include #include #include -#include #include #include +#include #include #include "rpc_manager.h" @@ -282,24 +282,20 @@ object_to_xmlrpc(xmlrpc_env* env, const torrent::Object& object) { // The versions that support I8 do implicit utf-8 validation. xmlrpc_value* result = xmlrpc_string_new(env, object.as_string().c_str()); #else + xmlrpc_value* result{}; + // In older versions, xmlrpc-c doesn't validate the utf-8 encoding itself. xmlrpc_validate_utf8(env, object.as_string().c_str(), object.as_string().length()); - xmlrpc_value* result = env->fault_occurred ? NULL : xmlrpc_string_new(env, object.as_string().c_str()); + if (!env->fault_occurred) + result = xmlrpc_string_new(env, object.as_string().c_str()); #endif if (env->fault_occurred) { xmlrpc_env_clean(env); xmlrpc_env_init(env); - const std::string& str = object.as_string(); - char buffer[str.size() + 1]; - char* dst = buffer; - for (char itr : str) - *dst++ = ((itr < 0x20 && itr != '\r' && itr != '\n' && itr != '\t') || (itr & 0x80)) ? '?' : itr; - *dst = 0; - - result = xmlrpc_string_new(env, buffer); + return xmlrpc_string_new(env, torrent::utils::string_with_escape_codes(object.as_string()).c_str()); } return result; diff --git a/src/ui/download_list.cc b/src/ui/download_list.cc index 81eef796..20417214 100644 --- a/src/ui/download_list.cc +++ b/src/ui/download_list.cc @@ -116,7 +116,7 @@ DownloadList::activate_display(Display displayType) { m_uiArray[m_state] = NULL; break; - + case DISPLAY_DOWNLOAD_LIST: m_uiArray[DISPLAY_DOWNLOAD_LIST]->disable(); @@ -130,7 +130,7 @@ DownloadList::activate_display(Display displayType) { case DISPLAY_STRING_LIST: m_uiArray[m_state]->disable(); break; - + default: break; } @@ -152,7 +152,7 @@ DownloadList::activate_display(Display displayType) { download->activate(m_frame); download->slot_exit(std::bind(&DownloadList::activate_display, this, DISPLAY_DOWNLOAD_LIST)); - + m_uiArray[DISPLAY_DOWNLOAD] = download; break; } @@ -273,7 +273,7 @@ DownloadList::receive_exit_input(Input type) { set_escdelay(1000); input::TextInput* input = control->ui()->current_input(); - + // We should check that this object is the one holding the input. if (input == NULL) return; diff --git a/src/ui/download_list.h b/src/ui/download_list.h index 319a3fc5..b5e4d406 100644 --- a/src/ui/download_list.h +++ b/src/ui/download_list.h @@ -1,37 +1,3 @@ -// rTorrent - BitTorrent client -// Copyright (C) 2005-2011, Jari Sundell -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// In addition, as a special exception, the copyright holders give -// permission to link the code of portions of this program with the -// OpenSSL library under certain conditions as described in each -// individual source file, and distribute linked combinations -// including the two. -// -// You must obey the GNU General Public License in all respects for -// all of the code used other than OpenSSL. If you modify file(s) -// with this exception, you may extend this exception to your version -// of the file(s), but you are not obligated to do so. If you do not -// wish to do so, delete this exception statement from your version. -// If you delete this exception statement from all source files in the -// program, then also delete it here. -// -// Contact: Jari Sundell - - #ifndef RTORRENT_UI_DOWNLOAD_LIST_H #define RTORRENT_UI_DOWNLOAD_LIST_H diff --git a/src/ui/root.cc b/src/ui/root.cc index e491f0e1..1fdbdb6d 100644 --- a/src/ui/root.cc +++ b/src/ui/root.cc @@ -83,13 +83,13 @@ Root::init(Control* c) { m_downloadList = std::make_unique(); - display::Frame* rootFrame = m_control->display()->root_frame(); + auto root_frame = m_control->display()->root_frame(); - rootFrame->initialize_row(5); - rootFrame->frame(0)->initialize_window(m_windowTitle.get()); - rootFrame->frame(2)->initialize_window(m_windowHttpQueue.get()); - rootFrame->frame(3)->initialize_window(m_windowInput.get()); - rootFrame->frame(4)->initialize_window(m_windowStatusbar.get()); + root_frame->initialize_row(5); + root_frame->frame(0)->initialize_window(m_windowTitle.get()); + root_frame->frame(2)->initialize_window(m_windowHttpQueue.get()); + root_frame->frame(3)->initialize_window(m_windowInput.get()); + root_frame->frame(4)->initialize_window(m_windowStatusbar.get()); m_windowTitle->set_active(true); m_windowStatusbar->set_active(true); @@ -97,7 +97,7 @@ Root::init(Control* c) { setup_keys(); - m_downloadList->activate(rootFrame->frame(1)); + m_downloadList->activate(root_frame->frame(1)); } void @@ -111,7 +111,14 @@ Root::cleanup() { m_control->display()->root_frame()->clear(); m_control->input()->erase(&m_bindings); - m_control = NULL; + // Destroy windows in reverse order of creation. + m_windowStatusbar = nullptr; + m_windowInput = nullptr; + m_windowHttpQueue = nullptr; + m_windowTitle = nullptr; + m_downloadList = nullptr; + + m_control = nullptr; } const char*