[Reviewer: Matt] Prevent segfaults caused by keeping a reference to a stack variable

Fixes https://github.com/Metaswitch/homestead/issues/59