Merge "Fix some memory leaks, potential errors." am: 9d239ec6a5 am: 60d677147e am: 0da25d6feb
am: d166883584

Change-Id: Ic1c946d8e099d77bb4e2a316aa4944095815bb6c