fdo#39440 sc: reduce scope of local variables

This addresses some cppcheck warnings.

Change-Id: Icd031be4aeec07ba60804923e3506d64cf876dd8