Bug 455625

Summary: Deleting copied file triggers Klipper::checkClipData -> Klipper::setClipboard -> repeat storm with memleak of QMimeData objects
Product: [Plasma] plasmashell Reporter: Philipp Knechtges <philipp-dev>
Component: ClipboardAssignee: Plasma Bugs List <plasma-bugs>
Status: RESOLVED DUPLICATE    
Severity: normal CC: qydwhotmail
Priority: NOR    
Version: 5.24.4   
Target Milestone: 1.0   
Platform: Fedora RPMs   
OS: Linux   
Latest Commit: Version Fixed In:

Description Philipp Knechtges 2022-06-19 23:27:16 UTC
SUMMARY
This bug report potentially reveals two issues:
- An infinite loop in Klipper, if the clip data is an deleted file.
- A memleak in Klipper::checkClipData or Klipper::setClipboard when dealing with QMimeData

STEPS TO REPRODUCE
(0. Optionally start plasmashell with environment variable QT_LOGGING_RULES="org.kde.klipper.debug=true" set)
1. Open Dolphin, create some temporary file. Let's call it "a.txt"
2. "Ctrl+C" this file "a.txt".
3. Now delete the "a.txt" file with "Shift+DEL".
4. Watch the memory consumption of plasmashell grow indefinitely.
5. "Ctrl+C" sth else and observe how the growth stops.

OBSERVED RESULT
1. Watch memory consumption of plasmashell grow
2. Qt logging output will yield a loop of the following
    org.kde.klipper: Checking clip data
    org.kde.klipper: was empty. Retried, now   still empty
    org.kde.klipper: Resetting clipboard (Prevent empty clipboard)
    org.kde.klipper: Setting clipboard to < "file:///home/asd/a.txt" >
    org.kde.klipper: Checking clip data
    org.kde.klipper: was empty. Retried, now   still empty
    org.kde.klipper: Resetting clipboard (Prevent empty clipboard)
    org.kde.klipper: Setting clipboard to < "file:///home/asd/a.txt" >
    org.kde.klipper: Checking clip data
    org.kde.klipper: was empty. Retried, now   still empty
    org.kde.klipper: Resetting clipboard (Prevent empty clipboard)
    org.kde.klipper: Setting clipboard to < "file:///home/asd/a.txt" >
    org.kde.klipper: Checking clip data
    org.kde.klipper: was empty. Retried, now   still empty
    org.kde.klipper: Resetting clipboard (Prevent empty clipboard)
    org.kde.klipper: Setting clipboard to < "file:///home/asd/a.txt" >
    org.kde.klipper: Checking clip data
    org.kde.klipper: was empty. Retried, now   still empty
    org.kde.klipper: Resetting clipboard (Prevent empty clipboard)
    org.kde.klipper: Setting clipboard to < "file:///home/asd/a.txt" >

EXPECTED RESULT
- no memleak in plasmashell

SOFTWARE/OS VERSIONS
Windows: 
macOS: 
Linux/KDE Plasma: 
(available in About System)
KDE Plasma Version: 
KDE Frameworks Version: 
Qt Version: 

ADDITIONAL INFORMATION
Attaching to plasmashell with heaptrack reveals that the leaks come from QMimeData::QMimeData() and QMimeData::setData calls. Unfortunately, the rest of the heaptrack log is not so useful, since heaptrack mixes up symbols for .so files with dwarf version 6 debug info.
Comment 1 Fushan Wen 2022-06-20 01:59:07 UTC

*** This bug has been marked as a duplicate of bug 454590 ***
Comment 2 Philipp Knechtges 2022-06-20 08:12:19 UTC
Looking at the supposedly solving fix in https://invent.kde.org/frameworks/kguiaddons/-/commit/04ddcecb5c91a79bce7443e2c43ed93450f435b1 , which was discussed in the bug 455625, it appreas to me that this probably only fixes the memleak.

The issue of having an infinite loop in plasma_engine_clipboard.so should then still persist. Hence, I would suggest to reopen the bug.