Don't use negative gas index

This shouldn't happen, but in case we run out of gases we shouldn't use
the negative gas index (which is the error return of get_gas_idx()) for
the array. Let's fall back to the (incorrect) first gas.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Don't use error after free

We need to reset the error pointer to NULL for this to work.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Fix possibly uninitialized value

I'm not sure about this one. It's possible that there's something
happening behind the scenes that I don't understand. But let's just
initialize this to 0 and be sure.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>