Correct patch of wine/dlls/ntdll path.c

Thomas Mertes thomas.mertes at gmx.at
Fri Nov 21 02:34:27 CST 2003


I think this Patch of dlls/ntdll/path.c is not correct:

-                name = (WCHAR*)RtlReAllocateHeap(ntdll_get_process_heap(),
0,
-                                                 name, (needed + filelen) *
sizeof(WCHAR));
+                if (!name) name = RtlAllocateHeap(GetProcessHeap(), 0,
+                                                  (needed + filelen) *
sizeof(WCHAR));
+                else
+                {
+                    WCHAR *newname = RtlReAllocateHeap(GetProcessHeap(), 0,
name,
+                                                       (needed + filelen) *
sizeof(WCHAR));
+                    if (!newname) RtlFreeHeap(GetProcessHeap(), 0, name);
+                    name = newname;
+                }

I think releasing name is not correct since newname can be identical to
name.
In my opinion the following patch would have been ok:

-                name = (WCHAR*)RtlReAllocateHeap(ntdll_get_process_heap(),
0,
-                                                 name, (needed + filelen) *
sizeof(WCHAR));
+                if (name == NULL) {
+                    name = RtlAllocateHeap(GetProcessHeap(), 0,
+                                           (needed + filelen) *
sizeof(WCHAR));
+                } else {
+                    name = RtlReAllocateHeap(GetProcessHeap(), 0, name,
+                                             (needed + filelen) *
sizeof(WCHAR));
+                } /* if */

To correct the wrong patch, I suggest the following patch (made by hand &
not tested):

Changelog:
	Thomas Mertes <thomas.mertes at gmx.at>
	Correct use of RtlAllocateHeap() and RtlReAllocateHeap().

Index: wine/dlls/ntdll/path.c
diff -u wine/dlls/ntdll/path.c:1.11 wine/dlls/ntdll/path.c:1.12
--- wine/dlls/ntdll/path.c:1.11	Fri Nov 21 09:24:47 2003
+++ wine/dlls/ntdll/path.c	Fri Nov 21 09:24:47 2003
@@ -282,15 +282,13 @@
             for (needed = 0, ptr = paths; *ptr != 0 && *ptr++ != ';';
needed++);
             if (needed + filelen > allocated)
             {
-                if (!name) name = RtlAllocateHeap(GetProcessHeap(), 0,
-                                                  (needed + filelen) *
sizeof(WCHAR));
-                else
-                {
-                    WCHAR *newname = RtlReAllocateHeap(GetProcessHeap(), 0,
name,
-                                                       (needed + filelen) *
sizeof(WCHAR));
-                    if (!newname) RtlFreeHeap(GetProcessHeap(), 0, name);
-                    name = newname;
-                }
+                if (name == NULL) {
+                    name = RtlAllocateHeap(GetProcessHeap(), 0,
+                                           (needed + filelen) *
sizeof(WCHAR));
+                } else {
+                    name = RtlReAllocateHeap(GetProcessHeap(), 0, name,
+                                             (needed + filelen) *
sizeof(WCHAR));
+                } /* if */
                 if (!name) return 0;
                 allocated = needed + filelen;
             }

Greetings
Thomas Mertes

-- 
GMX Weihnachts-Special: Seychellen-Traumreise zu gewinnen!

Rentier entlaufen. Finden Sie Rudolph! Als Belohnung winken
tolle Preise. http://www.gmx.net/de/cgi/specialmail/

+++ GMX - die erste Adresse für Mail, Message, More! +++




More information about the wine-patches mailing list