Fix some miscellaneous memory/reference leaks