Bug 345860

Summary: KZoneAllocator eats up too much memory on Windows
Product: [Frameworks and Libraries] frameworks-kcompletion Reporter: Andrius <andriusmao>
Component: generalAssignee: David Gil <davidgiloliva>
Status: RESOLVED FIXED    
Severity: critical CC: andriusmao, kde-windows, kdelibs-bugs, kfunk, simonandric5
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Microsoft Windows   
OS: Microsoft Windows   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Andrius 2015-04-04 12:06:33 UTC
Any app which uses KCompletion (e.g.: Kate) gets to use > 4GB memory then crashes my entire machine if I'm not quick enough to kill it. KZoneAllocator looks to be the culprit since by removing KCompTreeNode's custom operator new and delete does the trick.

Reproducible: Always

Steps to Reproduce:
1. Have KCompletion installed
2. Start Kate

Actual Results:  
My machine hangs due to eating a ton of memory and I need to force reboot.

Expected Results:  
Using more memory than the KZoneAllocator-less version but not that much.

Self compiled current git master version.
Comment 1 Andrius 2015-04-04 12:12:17 UTC
MSVC 2013 Memory dump file.
https://drive.google.com/file/d/0B8v2oXr-gdg5UjItZk5oYkZPMWc/view?usp=sharing
Comment 2 David Gil 2015-04-05 07:49:04 UTC
Hi!

Thanks for reporting. Could you please attach the patch you've made to remove KCompTreeNode's custom operator new and delete?

When I took over the maintenance of KCompletion I did a general cleanup, except for KZoneAllocator and related classes. I didn't dare to touch them and assumed they worked. Now I'm studying them to see if I find something suspicious.

Besides, I don't have any Windows machine to compile it, test and confirm. Someone else will have to help here.
Comment 3 Kevin Funk 2015-04-07 08:14:16 UTC
How long does it take from starting Kate until running out of memory? Is it instant or after some time of usage?
Comment 4 Andrius 2015-04-07 11:22:30 UTC
(In reply to Kevin Funk from comment #3)
> How long does it take from starting Kate until running out of memory? Is it
> instant or after some time of usage?

It grows as soon as it starts, taking ~20 seconds to render my computer unusable. The same happens with Qt designer as soon as it starts loading the available plugins (KCompletion again appears in the memory dump file).
Comment 5 Kevin Funk 2015-08-23 21:27:15 UTC
I think we've found the issue. Will post a patch soonish.
Comment 6 Kevin Funk 2015-08-24 12:37:34 UTC
Git commit 05167e5bf563f3b9b2465e9da2ecf1e4a86a0d4d by Kevin Funk.
Committed on 24/08/2015 at 12:37.
Pushed by kfunk into branch 'master'.

Fix bad behavior / running OOM on Windows

When testing KDevelop on Windows we sometimes experienced excessive use
of memory (> 2 gigs of RAM allocated). This patch appears to fix the
issue.

Compiler warnings didn't sound promising either:
Z:\kderoot\download\git\kcompletion\src\kzoneallocator.cpp(129):
warning C4319: '~': zero extending 'unsigned long' to 'quintptr' of greater size
Z:\kderoot\download\git\kcompletion\src\kzoneallocator.cpp(206):
warning C4319: '~': zero extending 'unsigned long' to 'quintptr' of greater size
Z:\kderoot\download\git\kcompletion\src\kzoneallocator.cpp(256):
warning C4267: '+=': conversion from 'size_t' to 'unsigned long', possible loss of data
REVIEW: 124896

M  +3    -3    src/kzoneallocator.cpp

http://commits.kde.org/kcompletion/05167e5bf563f3b9b2465e9da2ecf1e4a86a0d4d