Fixed memory leak from usage of static function