Fix memory leak when main loop is stopped in the middle of a transaction

Change-Id: I9cd6af9f703fa06050189966a36b0c365779d340