Merge "Fix some memory leaks, potential errors."
am: 9d239ec6a5

Change-Id: Iefc25a779c07a80457cc6ee6f6cb269655a05ccd