Fix memory leaks

Change-Id: Id67d5375bedc6e6c10082d9c5ee69d6e932be158