[PATCH 3/5] wordpad: Use CRT allocation functions.

Nikolay Sivov wine at gitlab.winehq.org
Tue Jul 5 01:48:22 CDT 2022


From: Nikolay Sivov <nsivov at codeweavers.com>

Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
---
 programs/wordpad/print.c    |  8 +++-----
 programs/wordpad/registry.c |  6 ++----
 programs/wordpad/wordpad.c  | 34 ++++++++++++++++------------------
 programs/wordpad/wordpad.h  |  2 ++
 4 files changed, 23 insertions(+), 27 deletions(-)

diff --git a/programs/wordpad/print.c b/programs/wordpad/print.c
index acc583eefc5..d73c2d7757e 100644
--- a/programs/wordpad/print.c
+++ b/programs/wordpad/print.c
@@ -749,7 +749,7 @@ void close_preview(HWND hMainWnd)
     preview.window.right = 0;
     preview.window.bottom = 0;
     preview.page = 0;
-    HeapFree(GetProcessHeap(), 0, preview.pageEnds);
+    free(preview.pageEnds);
     preview.pageEnds = NULL;
     preview.pageCapacity = 0;
     if (preview.zoomlevel > 0)
@@ -783,13 +783,11 @@ static void draw_preview(HWND hEditorWnd, FORMATRANGE* lpFr, RECT* paper, int pa
     if (!preview.pageEnds)
     {
         preview.pageCapacity = 32;
-        preview.pageEnds = HeapAlloc(GetProcessHeap(), 0,
-                                    sizeof(int) * preview.pageCapacity);
+        preview.pageEnds = malloc(sizeof(int) * preview.pageCapacity);
         if (!preview.pageEnds) return;
     } else if (page >= preview.pageCapacity) {
         int *new_buffer;
-        new_buffer = HeapReAlloc(GetProcessHeap(), 0, preview.pageEnds,
-                                 sizeof(int) * preview.pageCapacity * 2);
+        new_buffer = realloc(preview.pageEnds, sizeof(int) * preview.pageCapacity * 2);
         if (!new_buffer) return;
         preview.pageCapacity *= 2;
         preview.pageEnds = new_buffer;
diff --git a/programs/wordpad/registry.c b/programs/wordpad/registry.c
index 138111614bf..2de81c5d583 100644
--- a/programs/wordpad/registry.c
+++ b/programs/wordpad/registry.c
@@ -51,9 +51,7 @@ static LRESULT registry_get_handle(HKEY *hKey, LPDWORD action, LPCWSTR subKey)
         if(subKey)
         {
             WCHAR backslash[] = {'\\',0};
-            key = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
-                            (lstrlenW(wszProgramKey)+lstrlenW(subKey)+lstrlenW(backslash)+1)
-                                    *sizeof(WCHAR));
+            key = calloc(lstrlenW(wszProgramKey)+lstrlenW(subKey)+lstrlenW(backslash)+1, sizeof(WCHAR));
 
             if(!key)
                 return 1;
@@ -73,7 +71,7 @@ static LRESULT registry_get_handle(HKEY *hKey, LPDWORD action, LPCWSTR subKey)
         }
 
         if(subKey)
-            HeapFree(GetProcessHeap(), 0, key);
+            free(key);
 
         return ret;
 }
diff --git a/programs/wordpad/wordpad.c b/programs/wordpad/wordpad.c
index 7f79eccc8bb..4a3aa2375bf 100644
--- a/programs/wordpad/wordpad.c
+++ b/programs/wordpad/wordpad.c
@@ -239,8 +239,7 @@ static void set_caption(LPCWSTR wszNewFileName)
     else
         wszNewFileName = file_basename((LPWSTR)wszNewFileName);
 
-    wszCaption = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
-                lstrlenW(wszNewFileName)*sizeof(WCHAR)+sizeof(wszSeparator)+sizeof(wszAppTitle));
+    wszCaption = calloc(1, lstrlenW(wszNewFileName)*sizeof(WCHAR)+sizeof(wszSeparator)+sizeof(wszAppTitle));
 
     if(!wszCaption)
         return;
@@ -253,7 +252,7 @@ static void set_caption(LPCWSTR wszNewFileName)
 
     SetWindowTextW(hMainWnd, wszCaption);
 
-    HeapFree(GetProcessHeap(), 0, wszCaption);
+    free(wszCaption);
 }
 
 static BOOL validate_endptr(LPCWSTR endptr, UNIT *punit)
@@ -615,8 +614,8 @@ static BOOL array_reserve(void **elements, size_t *capacity, size_t count, size_
     if (new_capacity < count)
         new_capacity = max_capacity;
 
-    new_elements = *elements ? HeapReAlloc(GetProcessHeap(), 0, *elements, new_capacity * size) :
-            HeapAlloc(GetProcessHeap(), 0, new_capacity * size);
+    new_elements = *elements ? realloc(*elements, new_capacity * size) :
+            malloc(new_capacity * size);
     if (!new_elements)
         return FALSE;
 
@@ -638,7 +637,7 @@ static void add_font(struct font_array *fonts, LPCWSTR fontName, DWORD fontType,
         fontHeight = ntmc->ntmTm.tmHeight - ntmc->ntmTm.tmInternalLeading;
 
     idx = fonts->count;
-    fonts->fonts[idx].name = HeapAlloc( GetProcessHeap(), 0, (lstrlenW(fontName) + 1)*sizeof(WCHAR) );
+    fonts->fonts[idx].name = malloc((lstrlenW(fontName) + 1)*sizeof(WCHAR) );
     lstrcpyW( fonts->fonts[idx].name, fontName );
     fonts->fonts[idx].lParam = MAKELONG(fontType, fontHeight);
 
@@ -685,7 +684,7 @@ static void populate_font_list(HWND hListWnd)
     {
         if (!lstrcmpiW(font_array.fonts[i].name, font_array.fonts[j].name))
         {
-            HeapFree(GetProcessHeap(), 0, font_array.fonts[i].name);
+            free(font_array.fonts[i].name);
             font_array.fonts[i].name = NULL;
         }
         else if (++j != i)
@@ -707,9 +706,9 @@ static void populate_font_list(HWND hListWnd)
 
         SendMessageW(hListWnd, CBEM_INSERTITEMW, 0, (LPARAM)&cbitem);
 
-        HeapFree(GetProcessHeap(), 0, font_array.fonts[i].name);
+        free(font_array.fonts[i].name);
     }
-    HeapFree(GetProcessHeap(), 0, font_array.fonts);
+    free(font_array.fonts);
 
     ZeroMemory(&fmt, sizeof(fmt));
     fmt.cbSize = sizeof(fmt);
@@ -1015,8 +1014,7 @@ static BOOL prompt_save_changes(void)
         else
             displayFileName = file_basename(wszFileName);
 
-        text = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
-                         (lstrlenW(displayFileName)+lstrlenW(wszSaveChanges))*sizeof(WCHAR));
+        text = calloc(lstrlenW(displayFileName)+lstrlenW(wszSaveChanges), sizeof(WCHAR));
 
         if(!text)
             return FALSE;
@@ -1025,7 +1023,7 @@ static BOOL prompt_save_changes(void)
 
         ret = MessageBoxW(hMainWnd, text, wszAppTitle, MB_YESNOCANCEL | MB_ICONEXCLAMATION);
 
-        HeapFree(GetProcessHeap(), 0, text);
+        free(text);
 
         switch(ret)
         {
@@ -2401,20 +2399,20 @@ static LRESULT OnCommand( HWND hWnd, WPARAM wParam, LPARAM lParam)
     case ID_EDIT_GETTEXT:
         {
         int nLen = GetWindowTextLengthW(hwndEditor);
-        LPWSTR data = HeapAlloc( GetProcessHeap(), 0, (nLen+1)*sizeof(WCHAR) );
+        LPWSTR data = malloc((nLen+1)*sizeof(WCHAR) );
         TEXTRANGEW tr;
 
         GetWindowTextW(hwndEditor, data, nLen+1);
         MessageBoxW(NULL, data, wszAppTitle, MB_OK);
 
-        HeapFree( GetProcessHeap(), 0, data);
-        data = HeapAlloc(GetProcessHeap(), 0, (nLen+1)*sizeof(WCHAR));
+        free(data);
+        data = malloc((nLen+1)*sizeof(WCHAR));
         tr.chrg.cpMin = 0;
         tr.chrg.cpMax = nLen;
         tr.lpstrText = data;
         SendMessageW(hwndEditor, EM_GETTEXTRANGE, 0, (LPARAM)&tr);
         MessageBoxW(NULL, data, wszAppTitle, MB_OK);
-        HeapFree( GetProcessHeap(), 0, data );
+        free(data);
 
         /* SendMessage(hwndEditor, EM_SETSEL, 0, -1); */
         return 0;
@@ -2449,12 +2447,12 @@ static LRESULT OnCommand( HWND hWnd, WPARAM wParam, LPARAM lParam)
         WCHAR *data = NULL;
 
         SendMessageW(hwndEditor, EM_EXGETSEL, 0, (LPARAM)&range);
-        data = HeapAlloc(GetProcessHeap(), 0, sizeof(*data) * (range.cpMax-range.cpMin+1));
+        data = malloc(sizeof(*data) * (range.cpMax-range.cpMin+1));
         SendMessageW(hwndEditor, EM_GETSELTEXT, 0, (LPARAM)data);
         sprintf(buf, "Start = %ld, End = %ld", range.cpMin, range.cpMax);
         MessageBoxA(hWnd, buf, "Editor", MB_OK);
         MessageBoxW(hWnd, data, wszAppTitle, MB_OK);
-        HeapFree( GetProcessHeap(), 0, data);
+        free(data);
         /* SendMessage(hwndEditor, EM_SETSEL, 0, -1); */
         return 0;
         }
diff --git a/programs/wordpad/wordpad.h b/programs/wordpad/wordpad.h
index 0baf8c924dd..6dae06b38eb 100644
--- a/programs/wordpad/wordpad.h
+++ b/programs/wordpad/wordpad.h
@@ -17,6 +17,8 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
+#include <stdlib.h>
+
 #include <windef.h>
 #include <winuser.h>
 
-- 
GitLab


https://gitlab.winehq.org/wine/wine/-/merge_requests/378



More information about the wine-devel mailing list