tools: Fix memory leak for functions "I" and "G".