Fix defects detected by static analyzer