Fix orphan lines wrongly associated to previous queries instead of temporary file and lock logged statement. Thanks to Den Untevskiy for the report.