smalloc: split out part of smrealloc() to avoid deep nesting and some minor adjustments