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>
(cherry picked from commit 18fdd0b3fd02a3c815d9d111277973cd14fa42a1)