msvcrt: sharing violation caused by duplicated hande in _get_osfhandle

Eric Pouech eric.pouech at wanadoo.fr
Sat Apr 22 08:53:47 CDT 2006


qingdoa daoo wrote:
> Hi,
> wine's implementation of _get_osfhandle is found to cause sharing 
> violation in some apps. The author commented this piece of code with a 
> block of FIXME
> warning about possible leakage. It turns out it's no just a matter of 
> leakage.
> 
> A simple test program
> ------------------------------------------------------------
> #include "windows.h"
> #include "io.h"
> #include "fcntl.h"
> #include "share.h"
> int main()
> {
>     int fd, bWritten;
>     fd = _sopen("foo", _O_CREAT|_O_RDWR,_SH_DENYRW, 0);
>     WriteFile((HANDLE)_get_osfhandle(fd), "bar", 3, &bWritten, NULL);
>     _close(fd);
>     fd = _open("foo", _O_RDONLY, 0);
>     _write(1, fd==-1? "F\n" : "S\n", 2);
> }
> ------------------------------------------------------------
> The second _open fails with builtin msvcrt, not with native one.
> 
> The comment  says that the duplication is to make an inheritable hande.
> With the recent change in msvcrt's io init procedure, that shouldn't be 
> a problem
> anymore.
> 
> ------------------------------------------------------------------------
> Blab-away for as little as 1¢/min. Make PC-to-Phone Calls 
> <http://us.rd.yahoo.com/mail_us/taglines/postman2/*http://us.rd.yahoo.com/evt=39663/*http://voice.yahoo.com> 
> using Yahoo! Messenger with Voice.
> 
> 
> ------------------------------------------------------------------------
> 
> 
you're right... we should simply return the handle in get_osfhandle 
without duplicating the handle
could you submit the patch (the code snipnet would also be appreciated 
in the regression test suite)

A+

-- 
Eric Pouech




More information about the wine-devel mailing list