Prevent possible invalid free() with logging.