<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><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>
<p>Anyway; looking at statResult():<br />
const UDSEntry &StatJob::statResult() const<br />
{</p>
<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);">return d_func()->m_statResult;</pre></div>
<p>}</p>
<p>it is returning a const &, and the docs say:</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>Call this in the slot connected to result, and only after making sure no error happened.</p></blockquote>
<p>here we used job->exec(), it may finish and get deleted; KJob docs say:</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>KJob and its subclasses are meant to be used in a fire-and-forget way. Jobs will delete themselves when they finish using deleteLater() (although this behaviour can be changed), so a job instance will disappear after the next event loop run.</p></blockquote>
<p>The test never failed before for me; but it seems I can trigger a SIGSEGV by running the test many times in a row; it's my "educated guess", sort of confirmed by using job->setAutoDelete(false), that the job may finish and get deleted by the time we call entry.numberValue() on line 1534.</p>
<p>So, to use job->statResult() to initialize a var &, that has to happen from a slot connected to result(); but if we call job->exec(), then later on we want to use the UDSEntry then we can't use var &, but rather take a copy.</p>
<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>
<p><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>, WDYT?</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>