From a820edea238ce378927bfd9270a9930334802f93 Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Wed, 22 Mar 2023 13:44:27 +0100 Subject: [PATCH] prevent memory leaks when re-adding devices --- bus.cpp | 30 ++++++++++++++++++++++++++++++ bus.h | 10 +++++----- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/bus.cpp b/bus.cpp index d9b1830..62936b6 100644 --- a/bus.cpp +++ b/bus.cpp @@ -41,6 +41,36 @@ bus::~bus() delete m; } +void bus::add_cpu(cpu *const c) +{ + delete this->c; + this->c = c; +} + +void bus::add_tm11(tm_11 *tm11) +{ + delete this->tm11; + this->tm11 = tm11; +} + +void bus::add_rk05(rk05 *rk05_) +{ + delete this->rk05_; + this->rk05_ = rk05_; +} + +void bus::add_rl02(rl02 *rl02_) +{ + delete this->rl02_; + this->rl02_ = rl02_; +} + +void bus::add_tty(tty *tty_) +{ + delete this->tty_; + this->tty_ = tty_; +} + void bus::clearmem() { m -> reset(); diff --git a/bus.h b/bus.h index f60921d..4f745b1 100644 --- a/bus.h +++ b/bus.h @@ -110,11 +110,11 @@ public: uint16_t get_console_leds() { return console_leds; } - void add_cpu(cpu *const c) { this -> c = c; } - void add_tm11(tm_11 *tm11) { this -> tm11 = tm11; } - void add_rk05(rk05 *rk05_) { this -> rk05_ = rk05_; } - void add_rl02(rl02 *rl02_) { this -> rl02_ = rl02_; } - void add_tty(tty *tty_) { this -> tty_ = tty_; } + void add_cpu(cpu *const c); + void add_tm11(tm_11 *tm11); + void add_rk05(rk05 *rk05_); + void add_rl02(rl02 *rl02_); + void add_tty(tty *tty_); cpu *getCpu() { return this->c; }