ahmadsamir added a comment.

  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).
  
  Anyway; looking at statResult():
  const UDSEntry &StatJob::statResult() const
  {
  
    return d_func()->m_statResult;
  
  }
  
  it is returning a const &, and the docs say:
  
  > Call this in the slot connected to result, and only after making sure no 
error happened.
  
  here we used job->exec(), it may finish and get deleted; KJob docs say:
  
  > 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.
  
  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.
  
  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.
  
  And maybe statResult() shouldn't return a reference (or a const reference for 
that matter, because if the caller uses 'entry = job->statResult()'
  then statResult() returning a const & doesn't make any difference if it's 
copied...).
  
  @dfaure, WDYT?

REPOSITORY
  R241 KIO

REVISION DETAIL
  https://phabricator.kde.org/D28478

To: ahmadsamir, #frameworks, dfaure, meven, bruns
Cc: kde-frameworks-devel, LeGast00n, cblack, GB_2, michaelh, ngraham, bruns

Reply via email to