Fix a few cppcheck warnings.

Use the proper data type in format functions and fix a resource leak.