Fix memory leaks

Change-Id: I1a045757cae2a9e6bfc51da02f94daf5449a1c79