From: dave AT roborat DOT demon DOT co DOT uk (Dave Scott) Newsgroups: comp.os.msdos.djgpp Subject: Bug: file left open in _check_v2_prog() Date: Wed, 08 Sep 1999 21:27:41 +0100 (BST) Organization: none Message-ID: <19990908.2027.13831snz@roborat.demon.co.uk> X-Trace: mail2news.demon.co.uk 936823181 mail2news:5862 mail2news mail2news.demon.co.uk X-Complaints-To: abuse AT demon DOT net X-Mail2News-Path: news.demon.net!tele-post-20.mail.demon.net!roborat.demon.co.uk X-Newsreader: SNews 1.30+mods(jlw990902/djgpp) Lines: 58 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com I think I've found a bug in the libc '_check_v2_prog' function (in the file src\libc\dos\process\chkv2prg.c from DJLSR202.ZIP) This function begins with :- const _v2_prog_type *_check_v2_prog(const char *program, int pf) ... if (program) { pf = open(program, O_RDONLY|O_BINARY); if (pf < 0) return &type; } and ends :- ... if (program) close(pf); However in between there are several places (I count 10) where the function can return *without closing* the 'pf' file handle... For example :- ... if (read(pf, header, sizeof(header)) != sizeof(header)) return &type; ... This came to light when using the 'system()' or 'spawn*()' functions to repeatedly invoke a *non-DJGPP* compiled program - i.e. a "standard" DOS .exe type. e.g. Something like :- while (ch != 27) // loop until escape pressed { system("qedit file.txt"); // invoke an editor on text file ch = getch() ... etc. After a certain number of times through the loop, the child sub process finds it has no free file handles, and hence cannot open the given file. The solution appears to be simply change each of the :- return &type; to :- { if (program) close(pf); return &type; } Can anyone confirm this is correct please, and if so is it worth me uploading a patch for this? -- ()---() (0 0) Dave Scott e-mail: dave AT roborat DOT demon DOT co DOT uk ----m-( )-m------------------------------------------------------------- =o=