tests: Add defer statements to close file descriptors
tests: Add defer statements to close file descriptors

Move the defer statements to close fds immediately
after they are opened, to make sure they get closed
in case of error occuring later on in the program flow.

Signed-off-by: Archana Shinde <047ac45ce396f63f3cf93ff43725668e736e0632@intel.com>

clearcontainers/proxy,clearcontainers/proxy