fdo#39440 sd: reduce scope of local variables

This addresses some cppcheck warnings.

Change-Id: I14107ca24aa98f4111f542c3999866eb1a93a72b