]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix leaks with timestamped_file
authorTom Tromey <tom@tromey.com>
Fri, 16 Jan 2026 16:17:50 +0000 (09:17 -0700)
committerTom Tromey <tom@tromey.com>
Mon, 9 Feb 2026 15:15:53 +0000 (08:15 -0700)
This changes timestamped_file to own the stream it wraps.  This is
done simply because it was appropriate for all the code using this
class.

Approved-By: Andrew Burgess <aburgess@redhat.com>
gdb/tui/tui-io.c
gdb/ui-file.h
gdb/ui.c

index 41704fc44d13771030e21ae64cd73a785fff625d..f673fbf36f6d2b3db240de327c66368e64dfc435 100644 (file)
@@ -940,7 +940,7 @@ tui_initialize_io (void)
   /* Let tui_stderr own ERR_OUT.  */
   tui_stderr = new logging_file<ui_file_up> (ui_file_up (err_out));
   tui_stdlog = (new timestamped_file
-               (new logging_file<ui_file *> (err_out, true)));
+               (std::make_unique<logging_file<ui_file *>> (err_out, true)));
   tui_out = new cli_ui_out (tui_stdout, 0);
 
   /* Using redirectable_stdout here is a hack.  This should probably
index 94897ff0b774c0e3f5e4ea30da674d441ea6327d..d5771635468c815742c76e718366c954a45bc569 100644 (file)
@@ -442,11 +442,11 @@ protected:
 /* A ui_file that optionally puts a timestamp at the start of each
    line of output.  */
 
-class timestamped_file : public wrapped_file<ui_file *>
+class timestamped_file : public wrapped_file<ui_file_up>
 {
 public:
-  explicit timestamped_file (ui_file *stream)
-    : wrapped_file (stream)
+  explicit timestamped_file (ui_file_up stream)
+    : wrapped_file (std::move (stream))
   {
   }
 
index 9d71135bc3683dc22697305a157be03826076105..c1fc92e4ee6cc323d429eef98f184b0b6cd0ae50 100644 (file)
--- a/gdb/ui.c
+++ b/gdb/ui.c
@@ -56,7 +56,7 @@ ui::ui (FILE *instream_, FILE *outstream_, FILE *errstream_)
     m_ui_stderr (new logging_file<ui_file_up>
                 (std::make_unique<stderr_file> (errstream))),
     m_ui_stdlog (new timestamped_file
-                (new logging_file<ui_file_up>
+                (std::make_unique<logging_file<ui_file_up>>
                  (std::make_unique<stderr_file> (errstream), true))),
     m_ui_stdtarg (m_ui_stderr)
 {