Fixed bug where resources were not properly released when encountering an error inside a transaction.