+2021-01-27  Lancelot SIX  <lsix@lancelotsix.com>
+
+       PR gdb/27133
+       * cli/cli-interp.c (cli_interp_base::set_logging): Ensure the
+       unique_ptr is released when the wrapped pointer is kept for later
+       use.
+
 2021-01-27  Matthew Malcomson  <matthew.malcomson@arm.com>
 
        * aarch64-tdep.c (aarch64_displaced_step_others): Account for
 
          saved_output.file_to_delete = tee;
        }
 
+      /* Make sure that the call to logfile's dtor does not delete the
+         underlying pointer if we still keep a reference to it.  If
+         logfile_p is not referenced as the file_to_delete, then either
+         the logfile is not used (no redirection) and it should be
+         deleted, or a tee took ownership of the pointer. */
+      if (logfile_p != nullptr && saved_output.file_to_delete == logfile_p)
+       logfile.release ();
+
       gdb_stdout = logging_redirect ? logfile_p : tee;
       gdb_stdlog = debug_redirect ? logfile_p : tee;
       gdb_stderr = logging_redirect ? logfile_p : tee;
 
+2021-01-27  Lancelot SIX  <lsix@lancelotsix.com>
+
+       PR gdb/27133
+       * gdb.base/ui-redirect.exp: Add test case that ensures that
+       redirecting both logging and debug does not cause gdb to crash.
+
+
 2021-01-27  Matthew Malcomson  <matthew.malcomson@arm.com>
 
        * gdb.arch/insn-reloc.c: Add tests for BR and BLR.
 
     gdb_test "set logging off" "Done logging to /dev/null\\."
     gdb_test "help" "List of classes of commands:.*"
 }
+
+with_test_prefix "redirect logging and debuging" {
+    gdb_test_no_output "set logging redirect on"
+    gdb_test_no_output "set logging debugredirect on"
+    gdb_test "set logging on" \
+    "Redirecting output to /dev/null.*Redirecting debug output to /dev/null\\."
+    gdb_test "set logging off" "Done logging to /dev/null\\."
+}