Fix valgring-detected errors