# Buggy code
def _do_close(self):
    """Helper function for closeEvent."""
    try:
        last_visible = objreg.get("last-visible-main-window")
        if self is last_visible:
            objreg.delete("last-visible-main-window")
    except KeyError:
        pass
    sessions.session_manager.save_last_window_session()
    self._save_geometry()
    log.destroy.debug("Closing window {}".format(self.win_id))
    self.tabbed_browser.shutdown()


# Traceback (subprocess.CalledProcessError)
10:46:58 DEBUG    init       app:process_pos_args:299 Startup cmd ':later 500 quit'
10:46:58 DEBUG    commands   command:run:541 command called: later ['500', 'quit']
10:46:58 DEBUG    commands   command:run:556 Calling qutebrowser.misc.utilcmds.later(500, 'quit', 0)
10:46:58 DEBUG    init       app:_process_args:243 Init finished after 11.500216s
10:46:58 DEBUG    init       app:init:199 Init done!
10:46:58 DEBUG    webview    browsertab:_set_load_status:927 load status for <qutebrowser.browser.webengine.webenginetab.WebEngineTab tab_id=0 url='about:blank'>: LoadStatus.loading
10:46:58 DEBUG    signals    signalfilter:_filter_signals:88 emitting: cur_load_status_changed(<LoadStatus.loading: 6>) (tab 0)
10:46:58 DEBUG    signals    signalfilter:_filter_signals:88 emitting: cur_load_started() (tab 0)
10:46:58 DEBUG    commands   command:run:541 command called: quit
10:46:58 DEBUG    commands   argparser:multitype_conv:158 Trying to parse None as <class 'NoneType'>
10:46:58 DEBUG    commands   command:run:556 Calling qutebrowser.app.Quitter.quit(<qutebrowser.app.Quitter object at 0x0000021F46BED9D8>, False, None)
10:46:58 DEBUG    destroy    app:shutdown:721 Shutting down with status 0, session None...
10:46:58 DEBUG    prompt     prompt:shutdown:139 Shutting down with loops []
10:46:58 DEBUG    destroy    app:_shutdown:749 Stage 2 of shutting down...
10:46:58 DEBUG    ipc        ipc:shutdown:404 Shutting down IPC (socket 0x7ff9d7453ce0)
10:46:58 DEBUG    save       savemanager:save:97 Save of yaml-config requested - dirty False, save_on_exit False, is_exit True, force False -> False
10:46:58 DEBUG    save       savemanager:save:97 Save of state-config requested - dirty False, save_on_exit True, is_exit True, force False -> True
10:46:58 DEBUG    save       savemanager:save:97 Save of command-history requested - dirty False, save_on_exit False, is_exit True, force False -> False
10:46:59 DEBUG    save       savemanager:save:97 Save of quickmark-manager requested - dirty False, save_on_exit False, is_exit True, force False -> False
10:46:59 DEBUG    save       savemanager:save:97 Save of bookmark-manager requested - dirty False, save_on_exit False, is_exit True, force False -> False
10:46:59 DEBUG    save       savemanager:save:97 Save of cookies requested - dirty False, save_on_exit False, is_exit True, force False -> False
10:46:59 DEBUG    destroy    app:_shutdown:764 Deferring QApplication::exit...
10:46:59 DEBUG    destroy    app:exit:828 Now calling QApplication::exit.
10:46:59 DEBUG    destroy    objreg:on_destroyed:125 schedule removal: download-model
10:46:59 DEBUG    destroy    objreg:on_destroyed:125 schedule removal: quitter
10:46:59 DEBUG    destroy    objreg:on_destroyed:125 schedule removal: command-history
10:46:59 DEBUG    destroy    objreg:on_destroyed:125 schedule removal: 0
10:46:59 DEBUG    destroy    objreg:on_destroyed:125 schedule removal: main-window
10:46:59 DEBUG    destroy    objreg:on_destroyed:125 schedule removal: last-focused-main-window
10:46:59 DEBUG    destroy    objreg:on_destroyed:125 schedule removal: last-visible-main-window
10:46:59 DEBUG    destroy    objreg:on_destroyed:125 schedule removal: message-bridge
10:46:59 DEBUG    destroy    objreg:on_destroyed:125 schedule removal: tabbed-browser
10:46:59 DEBUG    destroy    objreg:on_destroyed:125 schedule removal: status-command
10:46:59 DEBUG    destroy    objreg:on_destroyed:125 schedule removal: 0
10:46:59 DEBUG    destroy    objreg:on_destroyed:125 schedule removal: tab
10:46:59 DEBUG    misc       eventfilter:eventFilter:80 <PyQt5.QtWidgets.QWidget object at 0x0000021F4CAD3A68>: removed child <PyQt5.QtCore.QObject object at 0x0000021F4C9C8A68>
10:46:59 DEBUG    misc       eventfilter:eventFilter:80 <PyQt5.QtWidgets.QWidget object at 0x0000021F4CAD3A68>: removed child <PyQt5.QtWidgets.QWidget object at 0x0000021F4C8C1288>
Windows fatal exception: access violation

Current thread 0x00001ef0 (most recent call first):
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python37-x64\lib\subprocess.py", line 512, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['py', '-3', '-m', 'qutebrowser', '--temp-basedir', '--nowindow', '--debug', 'about:blank', ':later 500 quit']' returned non-zero exit status 3221225477.

# Fixed code
def _do_close(self):
    """Helper function for closeEvent."""
    try:
        last_visible = objreg.get("last-visible-main-window")
        if self is last_visible:
            objreg.delete("last-visible-main-window")
    except KeyError:
        pass
    sessions.session_manager.save_last_window_session()
    self._save_geometry()
    log.destroy.debug("Closing window {}".format(self.win_id))