Avoid leaking cursors

Adding try/finally blocks to make sure that cursor
resources are let go

Change-Id: I596074aa9ab5752f91a26b5a03e1f39c23c64a5f
Automatic translation import

Change-Id: I5d66d07ff7826979e6b27dd5e83acf3f3f9f2c44