tools: Fix a bug in closing connection with master

This commit fixes a problem in tools/main.cc where sometimes
connection to the master server was not closed properly.
E.g. mfssetgoal and mfsgetgoal would fail with multiple arguments.

Change-Id: I7a8d3f41e28554d480a63414c0f7fbf355e24dd7