Fix memory leaks

Change-Id: Ied2b622d4a1dd20a1b79c270aa7b4828e5c103f2