fix a few minor memory bugs

Change-Id: I33d29637a61cc60c3eeb7465309247209b181339