Modified to avoid creating unnecessary return object. Refs #9949.
Merge branch 'bugfix/9949_coverity_share_ptr' into develop