From 77f1ba2d66e0e1ec62e5d9dd75cc9bb7c64eb770 Mon Sep 17 00:00:00 2001 From: lyskov-ai <277346777+lyskov-ai@users.noreply.github.com> Date: Thu, 30 Apr 2026 16:36:15 -0400 Subject: [PATCH] Modernize copy prevention in basic_otstream and TracerImpl basic_otstream: replace private undefined copy ctor with explicit = delete in the public section for both copy ctor and copy assignment. Add a comment explaining why: the destructor calls delete this->rdbuf(), so a copy sharing the same buffer would cause a double-free. TracerImpl: move the already-deleted copy ctor from private to public and add the missing copy assignment = delete. --- source/src/basic/TracerImpl.hh | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/source/src/basic/TracerImpl.hh b/source/src/basic/TracerImpl.hh index dea83589372..fdff476342f 100644 --- a/source/src/basic/TracerImpl.hh +++ b/source/src/basic/TracerImpl.hh @@ -54,6 +54,9 @@ public: basic_otstream() : std::basic_ostream ( new basic_tstringbuf (this) ) {} ~basic_otstream() override { delete this->rdbuf(); } + // ~basic_otstream() calls delete this->rdbuf(); a copy would share the same buffer, causing a double-free. + basic_otstream( basic_otstream const & ) = delete; + basic_otstream & operator=( basic_otstream const & ) = delete; /// @brief Return true if inner string buffer is empty. bool is_flushed() const { @@ -68,13 +71,6 @@ protected: /// TracerImpl and TracerProxyImpl objects. virtual void t_flush(std::string const &) {}; -private: - basic_otstream(basic_otstream const & ); - - - /// Data members - /// @brief inner string buffer - //std::basic_stringbuf * tstringbuf_; }; @@ -150,6 +146,9 @@ public: ~TracerImpl() override; + TracerImpl( TracerImpl const & ) = delete; + TracerImpl & operator=( TracerImpl const & ) = delete; + /// @brief re-init using data from another tracer object. void init( TracerImpl const & tr ); @@ -270,9 +269,6 @@ protected: void t_flush(std::string const &) override; private: /// Functions - /// @brief copy constructor. - TracerImpl( TracerImpl const & tr ) = delete; - static OstreamPointer &final_stream(); /// @brief return true if channel is inside vector, some logic apply.