Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DolphinQt: Fix memory leaks #11726

Merged
merged 4 commits into from Apr 5, 2023
Merged

Conversation

mackal
Copy link
Contributor

@mackal mackal commented Apr 4, 2023

Various objects didn't have expected parent management or only conditionally used, resulting in them not being managed and leaking

Indirect leak of 16 byte(s) in 1 object(s) allocated from:
    #0 0x559caf9473dd in operator new(unsigned long) (/home/user/projects/dolphin/Build/Binaries/dolphin-emu+0x6c73dd)
    #1 0x559caf9c48cf in FilesystemWidget::CreateWidgets() /home/user/projects/dolphin/Source/Core/DolphinQt/Config/FilesystemWidget.cpp:59:18
    #2 0x559caf9c453b in FilesystemWidget::FilesystemWidget(std::shared_ptr<DiscIO::Volume>) /home/user/projects/dolphin/Source/Core/DolphinQt/Config/FilesystemWidget.cpp:48:3
    #3 0x559cafabacb2 in PropertiesDialog::PropertiesDialog(QWidget*, UICommon::GameFile const&) /home/user/projects/dolphin/Source/Core/DolphinQt/Config/PropertiesDialog.cpp:81:44
    #4 0x559cafc101a0 in GameList::OpenProperties() /home/user/projects/dolphin/Source/Core/DolphinQt/GameList/GameList.cpp:540:38
    #5 0x7fddd30767db  (/usr/lib64/libQt5Core.so.5+0x2b97db)
    #6 0x7fddd59cf7e1 in QAction::triggered(bool) (/usr/lib64/libQt5Widgets.so.5+0x15c7e1)
Indirect leak of 48 byte(s) in 1 object(s) allocated from:
    #0 0x55b7bf3f427d in operator new(unsigned long) (/home/user/projects/dolphin/Build/Binaries/dolphin-emu+0x6c427d)
    #1 0x55b7bf4f4934 in LogConfigWidget::CreateWidgets() /home/user/projects/dolphin/Source/Core/DolphinQt/Config/LogConfigWidget.cpp:49:23
    #2 0x55b7bf4f420e in LogConfigWidget::LogConfigWidget(QWidget*) /home/user/projects/dolphin/Source/Core/DolphinQt/Config/LogConfigWidget.cpp:28:3
    #3 0x55b7bf7271c8 in MainWindow::CreateComponents() /home/user/projects/dolphin/Source/Core/DolphinQt/MainWindow.cpp:416:29
    #4 0x55b7bf724cb2 in MainWindow::MainWindow(std::unique_ptr<BootParameters, std::default_delete<BootParameters>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) /home/user/projects/dolphin/Source/Core/DolphinQt/MainWindow.cpp:225:3
    #5 0x55b7bf72069a in main /home/user/projects/dolphin/Source/Core/DolphinQt/Main.cpp:258:16
    #6 0x7f37ba8c5911  (/lib64/libc.so.6+0x27911)
    #7 0x7f37ba8c59c4 in __libc_start_main (/lib64/libc.so.6+0x279c4)
Indirect leak of 48 byte(s) in 1 object(s) allocated from:
    #0 0x559d685823dd in operator new(unsigned long) (/home/user/projects/dolphin/Build/Binaries/dolphin-emu+0x6c73dd)
    #1 0x559d68a5c49e in InterfacePane::CreateInGame() /home/user/projects/dolphin/Source/Core/DolphinQt/Settings/InterfacePane.cpp:193:27
    #2 0x559d68a5491a in InterfacePane::CreateLayout() /home/user/projects/dolphin/Source/Core/DolphinQt/Settings/InterfacePane.cpp:94:3
    #3 0x559d68a5491a in InterfacePane::InterfacePane(QWidget*) /home/user/projects/dolphin/Source/Core/DolphinQt/Settings/InterfacePane.cpp:84:3
    #4 0x559d688ce5b1 in MainWindow::ShowSettingsWindow() /home/user/projects/dolphin/Source/Core/DolphinQt/MainWindow.cpp:1225:29
    #5 0x7f3b6f9587db  (/usr/lib64/libQt5Core.so.5+0x2b97db)
    #6 0x7f3b722b17e1 in QAction::triggered(bool) (/usr/lib64/libQt5Widgets.so.5+0x15c7e1)
Indirect leak of 48 byte(s) in 1 object(s) allocated from:
    #0 0x5621ae3543dd in operator new(unsigned long) (/home/user/projects/dolphin/Build/Binaries/dolphin-emu+0x6c73dd)
    #1 0x5621ae59581a in MemoryWidget::CreateWidgets() /home/user/projects/dolphin/Source/Core/DolphinQt/Debugger/MemoryWidget.cpp:252:24
    #2 0x5621ae590be3 in MemoryWidget::MemoryWidget(QWidget*) /home/user/projects/dolphin/Source/Core/DolphinQt/Debugger/MemoryWidget.cpp:52:3
    #3 0x5621ae6872e2 in MainWindow::CreateComponents() /home/user/projects/dolphin/Source/Core/DolphinQt/MainWindow.cpp:427:25
    #4 0x5621ae684d8f in MainWindow::MainWindow(std::unique_ptr<BootParameters, std::default_delete<BootParameters>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) /home/user/projects/dolphin/Source/Core/DolphinQt/MainWindow.cpp:231:3
    #5 0x5621ae68076a in main /home/user/projects/dolphin/Source/Core/DolphinQt/Main.cpp:258:16
    #6 0x7f987b61f911  (/lib64/libc.so.6+0x27911)
    #7 0x7f987b61f9c4 in __libc_start_main (/lib64/libc.so.6+0x279c4)
Indirect leak of 48 byte(s) in 1 object(s) allocated from:
    #0 0x5621ae3543dd in operator new(unsigned long) (/home/user/projects/dolphin/Build/Binaries/dolphin-emu+0x6c73dd)
    #1 0x5621ae595b7f in MemoryWidget::CreateWidgets() /home/user/projects/dolphin/Source/Core/DolphinQt/Debugger/MemoryWidget.cpp:257:24
    #2 0x5621ae590be3 in MemoryWidget::MemoryWidget(QWidget*) /home/user/projects/dolphin/Source/Core/DolphinQt/Debugger/MemoryWidget.cpp:52:3
    #3 0x5621ae6872e2 in MainWindow::CreateComponents() /home/user/projects/dolphin/Source/Core/DolphinQt/MainWindow.cpp:427:25
    #4 0x5621ae684d8f in MainWindow::MainWindow(std::unique_ptr<BootParameters, std::default_delete<BootParameters>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) /home/user/projects/dolphin/Source/Core/DolphinQt/MainWindow.cpp:231:3
    #5 0x5621ae68076a in main /home/user/projects/dolphin/Source/Core/DolphinQt/Main.cpp:258:16
    #6 0x7f987b61f911  (/lib64/libc.so.6+0x27911)
    #7 0x7f987b61f9c4 in __libc_start_main (/lib64/libc.so.6+0x279c4)

QTreeView::setModel doesn't transfer ownership of the object.

Setting the parent resolves this
The m_verbosity_debug button was only conditionally being added as
widget, this was done in order to hide the object, but this left it
unmanaged.

Unconditionally adding it to the layout and controlling it's visibility
will resolve these issues
The m_checkbox_lock_mouse QCheckBox was only conditionally being added
to the layout, leaving it unmanaged and leaking

Setting the parent will allow it to be managed.
QMenuBar::addMenu does not take ownership of the QMenu, setting their
parent allows them to be cleaned up
Copy link
Member

@lioncash lioncash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice catches!

@lioncash lioncash merged commit 25fba72 into dolphin-emu:master Apr 5, 2023
14 checks passed
@mackal mackal deleted the dolphinqt-memory-leaks branch April 5, 2023 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants