Fix segfault when creating payments

Closing the memory-mapped file too early was causing curl to read invalid memory and segfault.