jahnf / Projecteur

Linux Desktop Application for the Logitech Spotlight device (and similar devices) - Digital Laser Pointer
MIT License
379 stars 33 forks source link

Memory leak on Zoom preset #134

Closed mayanksuman closed 3 years ago

mayanksuman commented 3 years ago

Most of time, if someone enable Zoom preset, the application leak about 9 MB of memory.

To Reproduce

  1. Open projecteur, Gnome system monitor and connect spotlight USB.
  2. Make a couple of preset including Zoom preset in Spotlight tab.
  3. Go to Device tab and inside input mapping: map double click to cycle preset.
  4. Now, while enabling Zoom during preset cycling 9 MB of memory is leaked (on my system) most of time.

Desktop/Linux Environment (please complete the following information):

jahnf commented 3 years ago

Hi Mayank, thanks for reporting, I will see if I can reproduce this. How did you measure this? (Just the system process view in Gnome does not tell you the whole truth.) I will do test runs with valgrind.

mayanksuman commented 3 years ago

I investigated this issue further and found this block in valgrind log:

==16066== 8,294,400 bytes in 1 blocks are still reachable in loss record 26,451 of 26,451
==16066==    at 0x483877F: malloc (vg_replace_malloc.c:307)
==16066==    by 0x5C2E04D: QImageData::create(QSize const&, QImage::Format) (in /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.15.2)
==16066==    by 0x5C2E26A: QImage::QImage(QSize const&, QImage::Format) (in /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.15.2)
==16066==    by 0x5C2E2B2: QImage::QImage(int, int, QImage::Format) (in /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.15.2)
==16066==    by 0x5C2EB62: QImage::copy(QRect const&) const (in /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.15.2)
==16066==    by 0xA2BFA5B: ??? (in /usr/lib/x86_64-linux-gnu/libQt5XcbQpa.so.5.15.2)
==16066==    by 0xA2AD6F8: QXcbScreen::grabWindow(unsigned long long, int, int, int, int) const (in /usr/lib/x86_64-linux-gnu/libQt5XcbQpa.so.5.15.2)
==16066==    by 0x5C0BB3E: QScreen::grabWindow(unsigned long long, int, int, int, int) (in /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.15.2)
==16066==    by 0x18078E: LinuxDesktop::grabScreen(QScreen*) const (linuxdesktop.cc:122)
==16066==    by 0x1A7330: ProjecteurApplication::ProjecteurApplication(int&, char**, ProjecteurApplication::Options const&)::{lambda(bool)#17}::operator()(bool) const (projecteurapp.cc:224)
==16066==    by 0x1AFC29: QtPrivate::FunctorCall<QtPrivate::IndexesList<0>, QtPrivate::List<bool>, void, ProjecteurApplication::ProjecteurApplication(int&, char**, ProjecteurApplication::Options const&)::{lambda(bool)#17}>::call({lambda(bool)#17}&, void**) (qobjectdefs_impl.h:146)
==16066==    by 0x1AF4C0: void QtPrivate::Functor<ProjecteurApplication::ProjecteurApplication(int&, char**, ProjecteurApplication::Options const&)::{lambda(bool)#17}, 1>::call<QtPrivate::List<bool>, void>({lambda(bool)#17}&, void*, {lambda(bool)#17}&*) (qobjectdefs_impl.h:256)
==16066== 

The desktopPixmap for window is never freed after allocating it on (projecteurapp.cc:224).

jahnf commented 3 years ago

After a brief look, I don't see why this should not be freed. The desktopPixmap property of the window is just an alias for the pixmap property of a ProjecteurImage instance belonging to the QmlEngine (instantiated from QML), also the QPixMap member is a regular member of ProjecteurImage and not a a pointer to a Pixmap. The ProjecteurImage instance should be cleaned up by the QmlEngine on exit.

But I still need to have a closer look within the next week.

mayanksuman commented 3 years ago

But I still need to have a closer look within the next week.

No need. I am going to close this issue.

I cannot reproduce this issue. By mistake, I got the valgrind log (pasted above) by pressing Ctrl+C on terminal.