Fix failure to release temporary memory