Index: b/popen.c =================================================================== --- b/popen.c +++ b/popen.c @@ -145,7 +145,6 @@ } THREAD_UNLOCK(); - /* Parent; assume fdopen can't fail. */ if (*type == 'r') { iop = fdopen(pdes[0], type); (void)_close(pdes[1]); @@ -154,6 +153,13 @@ (void)_close(pdes[0]); } + /* Parent: adding check for fdopen failure. */ + if (iop == NULL) { + (void)_close(pdes[(*type == 'r') ? 0 : 1]); /* close used pipe-end */ + free(cur); + return (NULL); + } + /* Link into list of file descriptors. */ cur->fp = iop; cur->pid = pid;