Reduce scope of variables

Based on TortoiseSVN revision 25239

Signed-off-by: Sup Yut Sum <ch3cooli@gmail.com>
Don't assign NULL to an iterator

Based on TortoiseSVN revision 25237

Signed-off-by: Sup Yut Sum <ch3cooli@gmail.com>