KUDU-3520 Fix file descriptor leak in encryption

In PosixEnv, when creating new file handles, file descriptors are
created first, which are then passed to file handle objects, which close
the file descriptors in their destructors. With encryption enabled,
things can go wrong before they're passed to these objects, in which
case the file descriptors can be leaked due to returning from these
methods without the file handle objects being created.

This commit fixes this leak by closing the files on the failure cases.

Unfortunately, I couldn't reproduce the bug reported originally after
several attempts with different fd limits as if it was set too low, it
failed with a different error, and if it was set higher, it just didn't
fail. It looks like this was an edge case triggered by an unhappy
coincidence of multiple variables.

Change-Id: I2412429d4fe836b705296e9e30453d7c4d030cec
Reviewed-on: http://gerrit.cloudera.org:8080/20631
Reviewed-by: Alexey Serbin <alexey@apache.org>
Tested-by: Kudu Jenkins
1 file changed