[RESENT] Don't duplicate handles for _get_osfhandle
Uwe Bonnes
bon at elektron.ikp.physik.tu-darmstadt.de
Fri Feb 10 11:29:44 CST 2006
Changelog:
wine/dlls/msvcrt/file.c: _get_osfhandle
Don't duplicate handles, otherwise they leak
This time with test case that fails without the patch (but succeed with
native msvcrt).
--
Uwe Bonnes bon at elektron.ikp.physik.tu-darmstadt.de
Institut fuer Kernphysik Schlossgartenstrasse 9 64289 Darmstadt
--------- Tel. 06151 162516 -------- Fax. 06151 164321 ----------
Index: wine/dlls/msvcrt/file.c
===================================================================
RCS file: /home/wine/wine/dlls/msvcrt/file.c,v
retrieving revision 1.95
diff -u -w -r1.95 file.c
--- wine/dlls/msvcrt/file.c 10 Feb 2006 14:58:58 -0000 1.95
+++ wine/dlls/msvcrt/file.c 10 Feb 2006 17:24:53 -0000
@@ -1205,25 +1205,7 @@
*/
long _get_osfhandle(int fd)
{
- HANDLE hand = msvcrt_fdtoh(fd);
- HANDLE newhand = hand;
- TRACE(":fd (%d) handle (%p)\n",fd,hand);
-
- if (hand != INVALID_HANDLE_VALUE)
- {
- /* FIXME: I'm not convinced that I should be copying the
- * handle here - it may be leaked if the app doesn't
- * close it (and the API docs don't say that it should)
- * Not duplicating it means that it can't be inherited
- * and so lcc's wedit doesn't cope when it passes it to
- * child processes. I've an idea that it should either
- * be copied by CreateProcess, or marked as inheritable
- * when initialised, or maybe both? JG 21-9-00.
- */
- DuplicateHandle(GetCurrentProcess(),hand,GetCurrentProcess(),
- &newhand,0,TRUE,DUPLICATE_SAME_ACCESS);
- }
- return (long)newhand;
+ return (long) msvcrt_fdtoh(fd);
}
/*********************************************************************
Index: wine/dlls/msvcrt/tests/file.c
===================================================================
RCS file: /home/wine/wine/dlls/msvcrt/tests/file.c,v
retrieving revision 1.21
diff -u -w -r1.21 file.c
--- wine/dlls/msvcrt/tests/file.c 21 Nov 2005 11:58:11 -0000 1.21
+++ wine/dlls/msvcrt/tests/file.c 10 Feb 2006 17:24:53 -0000
@@ -455,6 +455,31 @@
ok(_unlink(fname3) == 0, "Couldn't unlink file named '%s'\n", fname3);
}
+static void test_osf_handle( void )
+{
+ char fname1[] = "empty3";
+ char fname2[] = "empty4";
+ static const char outbuffer[] = "0,1,2,3,4,5,6,7,8,9";
+ int fd, res;
+ long osfhandle;
+
+ fd = open (fname1, O_WRONLY | O_CREAT | O_BINARY, _S_IREAD |_S_IWRITE);
+ write (fd, outbuffer, sizeof (outbuffer));
+
+ /* Dangling _osf_handle shouldn't disturb operations after file close */
+ osfhandle = _get_osfhandle(fd);
+ close(fd);
+
+ res = rename(fname1, fname2);
+ ok(res == 0, "Rename failed errno %d strerror %s\n",errno, strerror(errno));
+
+ res = remove(fname2);
+ ok(res == 0, "Remove %s returned %d\n", fname2, res);
+
+ res = remove(fname1);
+ ok(res == -1, "Remove unexpected success for original name of renamed file\n");
+}
+
START_TEST(file)
{
int arg_c;
@@ -480,4 +505,5 @@
test_fgetwc();
test_file_put_get();
test_tmpnam();
+ test_osf_handle();
}
More information about the wine-patches
mailing list