<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.kde.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugs.kde.org/"
          
          maintainer="sysadmin@kde.org"
>

    <bug>
          <bug_id>316449</bug_id>
          
          <creation_ts>2013-03-10 06:56:11 +0000</creation_ts>
          <short_desc>Large memory leak when updating entries via data sources</short_desc>
          <delta_ts>2013-03-12 03:58:29 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>2</classification_id>
          <classification>Applications</classification>
          <product>tellico</product>
          <component>general</component>
          <version>2.3.7</version>
          <rep_platform>Unlisted Binaries</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>NOR</priority>
          <bug_severity>major</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>0</everconfirmed>
          <reporter name="Dominik Stadler">dominik.stadler</reporter>
          <assigned_to name="Robby Stephenson">robby</assigned_to>
          
          
          <cf_commitlink>http://commits.kde.org/tellico/301ed4cce8a4c4aafa46de647bcfc1d0d55d4306</cf_commitlink>
          <cf_versionfixedin>2.3.8</cf_versionfixedin>
          <cf_sentryurl></cf_sentryurl>
          <votes>0</votes>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1349382</commentid>
    <comment_count>0</comment_count>
    <who name="Dominik Stadler">dominik.stadler</who>
    <bug_when>2013-03-10 06:56:11 +0000</bug_when>
    <thetext>I have a large collection and when I update many entries via data sources in one go, I see a steady increase in memory usage until available memory runs out and finally the linux-oom-killer kicks in and forcefully closes tellico.

I see aprox. 1MB of memory leak per 10 entries being updated.

Reproducible: Always

Steps to Reproduce:
1. Open a sufficiently large collection of books
2. Select many entries and choose &quot;update entries -&gt; from all sources&quot;
3. Wait until memory runs out
Actual Results:  
tellico crashes/is killed by the linux oom-killer

Expected Results:  
memory should keep steady</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1349703</commentid>
    <comment_count>1</comment_count>
    <who name="Dominik Stadler">dominik.stadler</who>
    <bug_when>2013-03-10 23:25:24 +0000</bug_when>
    <thetext>I did some investigation and I have two suspects here: 

* xslthandler.cpp:233: The members m_docIn and m_docOut are only freed in the destructor, but overwritten with newly allocated objects, thus leaking two XML documents for every XSLT parsing.

I am currently testing a patch which get&apos;s rid of the members m_docIn and m_docOut completely and just keeps the documents locally and frees them immediately after the parse, they are not used any more anyway and thus it is generally a good idea to throw them away quickly rather than keeping them around.

* I don&apos;t know much about KDE&apos;s signals, but it looks to me like signalResultFound leaks FetchResults if the FetchDialog is not shown. 
When updating entries, the dialog is not displayed and thus the slot for &quot;ResultFound&quot; is not connected. However each fetcher allocates a FetchResult and passes it to the signal. I could not yet verify that it actually leaks, but valgrind reports some lost memory around that area...

    FetchResult* r = new FetchResult(...);
    emit signalResultFound(r);

I&apos;ll update here with patches if my changes work for my collections.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1349728</commentid>
    <comment_count>2</comment_count>
    <who name="Robby Stephenson">robby</who>
    <bug_when>2013-03-11 00:50:24 +0000</bug_when>
    <thetext>(In reply to comment #1)
&gt; * xslthandler.cpp:233: The members m_docIn and m_docOut are only freed in
&gt; the destructor, but overwritten with newly allocated objects, thus leaking
&gt; two XML documents for every XSLT parsing.
&gt; 
&gt; I am currently testing a patch which get&apos;s rid of the members m_docIn and
&gt; m_docOut completely and just keeps the documents locally and frees them
&gt; immediately after the parse, they are not used any more anyway and thus it
&gt; is generally a good idea to throw them away quickly rather than keeping them
&gt; around.

Sound appropriate. I did some refactoring of that class a while back and probably didn&apos;t realize I could potentially make m_docIn and m_docOut local variables.

&gt; * I don&apos;t know much about KDE&apos;s signals, but it looks to me like
&gt; signalResultFound leaks FetchResults if the FetchDialog is not shown. 
&gt; When updating entries, the dialog is not displayed and thus the slot for
&gt; &quot;ResultFound&quot; is not connected. However each fetcher allocates a FetchResult
&gt; and passes it to the signal. I could not yet verify that it actually leaks,
&gt; but valgrind reports some lost memory around that area...
&gt; 
&gt;     FetchResult* r = new FetchResult(...);
&gt;     emit signalResultFound(r);

Even though the dialog isn&apos;t shown, the updater still gets the new information from signalResultFound(). It could certainly be leaking, but it&apos;s not just because the dialog isn&apos;t used. The update job may not be deleting something that it should.

&gt; I&apos;ll update here with patches if my changes work for my collections.
Absolutely, thanks! Just in general, the fetch jobs aren&apos;t really written with large update loops in mind, but any memory leaks should definitely be fixed. The update job loop isn&apos;t all that efficient...one of these days, I may need to learn threads, too...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1349990</commentid>
    <comment_count>3</comment_count>
      <attachid>77962</attachid>
    <who name="Dominik Stadler">dominik.stadler</who>
    <bug_when>2013-03-11 18:08:26 +0000</bug_when>
    <thetext>Created attachment 77962
Fix large memory leak for every xslt transformation that is done, e.g. as part of fetches

I tested with the attached patch to free up the memory for the XML documents as early as possible. With this in place memory increase is a lot less, maybe even zero, fetching many entries at once now works for up to 1000 entries without much memory increase. 

I will probably take another look which items are still reported by valgrind now, but for my usage it should already suffice for now.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1350117</commentid>
    <comment_count>4</comment_count>
    <who name="Robby Stephenson">robby</who>
    <bug_when>2013-03-12 03:58:29 +0000</bug_when>
    <thetext>Git commit 301ed4cce8a4c4aafa46de647bcfc1d0d55d4306 by Robby Stephenson.
Committed on 12/03/2013 at 04:56.
Pushed by rstephenson into branch &apos;2.3&apos;.

Free xmlDoc memory as soon as possible in XSLTHandler

Make the xmlDoc pointers local and free them as soon as possible
instead of waiting for the XSLTHandler destructor

Patch from Dominik Stadler
FIXED-IN: 2.3.8

M  +20   -24   src/translators/xslthandler.cpp
M  +1    -3    src/translators/xslthandler.h

http://commits.kde.org/tellico/301ed4cce8a4c4aafa46de647bcfc1d0d55d4306</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>77962</attachid>
            <date>2013-03-11 18:08:26 +0000</date>
            <delta_ts>2013-03-11 18:08:26 +0000</delta_ts>
            <desc>Fix large memory leak for every xslt transformation that is done, e.g. as part of fetches</desc>
            <filename>tellico-Bug-316449-XSLTHandler-Memory-Leak.patch</filename>
            <type>text/plain</type>
            <size>3116</size>
            <attacher name="Dominik Stadler">dominik.stadler</attacher>
            
              <data encoding="base64">ZGlmZiAtLWdpdCBhL3NyYy90cmFuc2xhdG9ycy94c2x0aGFuZGxlci5jcHAgYi9zcmMvdHJhbnNs
YXRvcnMveHNsdGhhbmRsZXIuY3BwCmluZGV4IDA0YmI5Y2YuLmY1YzcxZmYgMTAwNjQ0Ci0tLSBh
L3NyYy90cmFuc2xhdG9ycy94c2x0aGFuZGxlci5jcHAKKysrIGIvc3JjL3RyYW5zbGF0b3JzL3hz
bHRoYW5kbGVyLmNwcApAQCAtODAsOSArODAsNyBAQCBYU0xUSGFuZGxlcjo6WE1MT3V0cHV0QnVm
ZmVyOjp+WE1MT3V0cHV0QnVmZmVyKCkgewogaW50IFhTTFRIYW5kbGVyOjpzX2luaXRDb3VudCA9
IDA7CiAKIFhTTFRIYW5kbGVyOjpYU0xUSGFuZGxlcihjb25zdCBRQnl0ZUFycmF5JiB4c2x0Rmls
ZV8pIDoKLSAgICBtX3N0eWxlc2hlZXQoMCksCi0gICAgbV9kb2NJbigwKSwKLSAgICBtX2RvY091
dCgwKSB7CisgICAgbV9zdHlsZXNoZWV0KDApIHsKICAgaW5pdCgpOwogICBRQnl0ZUFycmF5IGZp
bGUgPSBRVXJsOjp0b1BlcmNlbnRFbmNvZGluZyhRU3RyaW5nOjpmcm9tTG9jYWw4Qml0KHhzbHRG
aWxlXykpOwogICBpZighZmlsZS5pc0VtcHR5KCkpIHsKQEAgLTk3LDkgKzk1LDcgQEAgWFNMVEhh
bmRsZ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pOwogCiAgIHhzbHRTdHlsZXNoZWV0UHRyIG1fc3R5bGVzaGVl
dDsKLSAgeG1sRG9jUHRyIG1fZG9jSW47Ci0gIHhtbERvY1B0ciBtX2RvY091dDsKIAogICBRSGFz
aDxRQnl0ZUFycmF5LCBRQnl0ZUFycmF5PiBtX3BhcmFtczsKIAo=
</data>

          </attachment>
      

    </bug>

</bugzilla>