Fix ressource leaks

Change-Id: I3a201cfd924e467d605351782bd06874c2af725e

Patchset: 1
http://review.cyanogenmod.org/#/c/64251/