Close file descriptor after dup2

Close the file descriptor assgined by open if it
is not the same as the newfd.

Fixes coverity 1028694
Fixes #11607

(It seems likely that coverity will not agree that it is
fixed, since it will not recognize the belt and suspenders
checking of the fd being the value dup'ed to).

Signed-off-by: Stuart Morgan <smorgan@mythtv.org>