Fixed wrong return value and missing member copy.

Fixes issue 2965.
(cherry picked from commit c6df48f823f61d55762f75dc34747816172fee02)
Merge remote-tracking branch 'upstream/3.5.x' into 3.5_surfsara