<table><tr><td style="">ahmadsamir added a comment.
</td><a style="text-decoration: none; padding: 4px 8px; margin: 0 8px 8px; float: right; color: #464C5C; font-weight: bold; border-radius: 3px; background-color: #F7F7F9; background-image: linear-gradient(to bottom,#fff,#f1f0f1); display: inline-block; border: 1px solid rgba(71,87,120,.2);" href="https://phabricator.kde.org/D28478">View Revision</a></tr></table><br /><div><div><blockquote style="border-left: 3px solid #8C98B8;
color: #6B748C;
font-style: italic;
margin: 4px 0 12px 0;
padding: 8px 12px;
background-color: #F8F9FC;">
<div style="font-style: normal;
padding-bottom: 4px;">In <a href="https://phabricator.kde.org/D28478#645682" style="background-color: #e7e7e7;
border-color: #e7e7e7;
border-radius: 3px;
padding: 0 4px;
font-weight: bold;
color: black;text-decoration: line-through;">D28478#645682</a>, <a href="https://phabricator.kde.org/p/dfaure/" style="
border-color: #f1f7ff;
color: #19558d;
background-color: #f1f7ff;
border: 1px solid transparent;
border-radius: 3px;
font-weight: bold;
padding: 0 4px;">@dfaure</a> wrote:</div>
<div style="margin: 0;
padding: 0;
border: 0;
color: rgb(107, 116, 140);"><blockquote style="border-left: 3px solid #8C98B8;
color: #6B748C;
font-style: italic;
margin: 4px 0 12px 0;
padding: 8px 12px;
background-color: #F8F9FC;">
<div style="font-style: normal;
padding-bottom: 4px;">In <a href="https://phabricator.kde.org/D28478#645019" style="background-color: #e7e7e7;
border-color: #e7e7e7;
border-radius: 3px;
padding: 0 4px;
font-weight: bold;
color: black;text-decoration: line-through;">D28478#645019</a>, <a href="https://phabricator.kde.org/p/ahmadsamir/" style="
border-color: #f1f7ff;
color: #19558d;
background-color: #f1f7ff;
border: 1px solid transparent;
border-radius: 3px;
font-weight: bold;
padding: 0 4px;">@ahmadsamir</a> wrote:</div>
<div style="margin: 0;
padding: 0;
border: 0;
color: rgb(107, 116, 140);"><p>hmm... first this is a copy-paste "error" on my part, I personally never use & when the RHS is a temporary (I don't see the point).</p></div>
</blockquote>
<p>The point is to avoid a copy ;-)</p>
<p>If the RHS is a value, this extends its lifetime.<br />
But if it's a reference itself, then indeed we depend on its lifetime....</p>
<blockquote style="border-left: 3px solid #a7b5bf; color: #464c5c; font-style: italic; margin: 4px 0 12px 0; padding: 4px 12px; background-color: #f8f9fc;"><div class="remarkup-code-block" style="margin: 12px 0;" data-code-lang="text" data-sigil="remarkup-code-block"><pre class="remarkup-code" style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; padding: 12px; margin: 0; background: rgba(71, 87, 120, 0.08);">the job may finish and get deleted by the time we call entry.numberValue() on line 1534.</pre></div></blockquote>
<p>That's not a "guess", it's confirmed by what ASAN tells us in its second backtrace.</p>
<blockquote style="border-left: 3px solid #a7b5bf; color: #464c5c; font-style: italic; margin: 4px 0 12px 0; padding: 4px 12px; background-color: #f8f9fc;"><p>And maybe statResult() shouldn't return a reference (or a const reference for that matter, because if the caller uses 'entry = job->statResult()'<br />
then statResult() returning a const & doesn't make any difference if it's copied...).</p></blockquote>
<p>Well you get two copies then, one at "return" and one at '=' (technically that's an assignment, unless entry is actually declared on the same line).</p></div>
</blockquote>
<p>I meant something like:<br />
const int i = foo();<br />
the return from foo() is copied into i and then it's gone.<br />
const int &i = foo();<br />
the return from foo() will be stored in a temporary, and it will stay around until i goes out of scope. So, there's only one "copy" of the return from foo() around, I'd rather take the one stored in i (<a href="https://herbsutter.com/2013/05/13/gotw-2-solution-temporary-objects/" class="remarkup-link" target="_blank" rel="noreferrer">https://herbsutter.com/2013/05/13/gotw-2-solution-temporary-objects/</a>); I know that's nitpicking, but anyway. So mainly when it's an initialisation rather than assignment. :)</p>
<blockquote style="border-left: 3px solid #a7b5bf; color: #464c5c; font-style: italic; margin: 4px 0 12px 0; padding: 4px 12px; background-color: #f8f9fc;"><p>Anyhow the fix is clear, remove the & :-)</p></blockquote>
<p>OK, will do.</p></div></div><br /><div><strong>REPOSITORY</strong><div><div>R241 KIO</div></div></div><br /><div><strong>REVISION DETAIL</strong><div><a href="https://phabricator.kde.org/D28478">https://phabricator.kde.org/D28478</a></div></div><br /><div><strong>To: </strong>ahmadsamir, Frameworks, dfaure, meven, bruns<br /><strong>Cc: </strong>kde-frameworks-devel, LeGast00n, cblack, GB_2, michaelh, ngraham, bruns<br /></div>