# File lib/rbreadline.rb, line 4770
  def readline_internal_teardown(eof)
    # Restore the original of this history line, iff the line that we
    #   are editing was originally in the history, AND the line has changed.
    entry = current_history()

    if (entry && @rl_undo_list)
      temp = @rl_line_buffer.delete(0.chr).dup
      rl_revert_line(1, 0)
      entry = replace_history_entry(where_history(), @rl_line_buffer, nil)
      entry = nil

      @rl_line_buffer = temp+0.chr
      temp = nil
    end

    # At any rate, it is highly likely that this line has an undo list.  Get
    #   rid of it now.
    if (@rl_undo_list)
      rl_free_undo_list()
    end
    # Restore normal cursor, if available.
    _rl_set_insert_mode(RL_IM_INSERT, 0)

    (eof ? nil : @rl_line_buffer.delete(0.chr))
  end