To me the new code seems broken. It keeps a fd open between libc calls. It requires endusershell() to be called later.
Not even close-on-exec can work here, because libc is remembering a FILE * referring to an open fd. Leaving a fd open between libc calls is verboten, unless there is tremendous cause. The old code does not require endusershell() to close the descriptor.