[rbp] Fixes for hangs and leaks in jpeg->texture code

This was reported by @MilhouseVH using his texture cache script:
./texturecache.py stress-test thumbnail 452 0.25 999 10

which stress tests the jpeg->texture code.
On current master this occasionally hangs or crashes.
Also if gpu memory is insufficient such that the error handling code is invoked we may not free the partially allocated resources.

With the patches, the stress test failures no longer occur.