Commit 33ae61d7 authored by Alex Henrie's avatar Alex Henrie Committed by Alexandre Julliard

winhlp32: Use standard C functions for memory allocation.

parent 803c616f
......@@ -22,6 +22,7 @@
#define WIN32_LEAN_AND_MEAN
#include <stdio.h>
#include <stdlib.h>
#include "windows.h"
#include "commdlg.h"
......@@ -48,14 +49,6 @@ static unsigned MACRO_NumLoaded /* = 0 */;
/******* helper functions *******/
static char* StrDup(const char* str)
{
char* dst;
dst=HeapAlloc(GetProcessHeap(),0,strlen(str)+1);
strcpy(dst, str);
return dst;
}
static WINHELP_BUTTON** MACRO_LookupButton(WINHELP_WINDOW* win, LPCSTR name)
{
WINHELP_BUTTON** b;
......@@ -81,7 +74,7 @@ void CALLBACK MACRO_CreateButton(LPCSTR id, LPCSTR name, LPCSTR macro)
size = sizeof(WINHELP_BUTTON) + strlen(id) + strlen(name) + strlen(macro) + 3;
button = HeapAlloc(GetProcessHeap(), 0, size);
button = malloc(size);
if (!button) return;
button->next = 0;
......@@ -239,7 +232,7 @@ static void CALLBACK MACRO_ChangeButtonBinding(LPCSTR id, LPCSTR macro)
size = sizeof(WINHELP_BUTTON) + strlen(id) +
strlen((*b)->lpszName) + strlen(macro) + 3;
button = HeapAlloc(GetProcessHeap(), 0, size);
button = malloc(size);
if (!button) return;
button->next = (*b)->next;
......@@ -612,17 +605,16 @@ static void CALLBACK MACRO_JumpID(LPCSTR lpszPathWindow, LPCSTR topic_id)
LPSTR tmp;
size_t sz;
tmp = HeapAlloc(GetProcessHeap(), 0, strlen(lpszPathWindow) + 1);
tmp = strdup(lpszPathWindow);
if (tmp)
{
strcpy(tmp, lpszPathWindow);
tmp[ptr - lpszPathWindow] = '\0';
ptr += tmp - lpszPathWindow; /* ptr now points to '>' in tmp buffer */
/* in some cases, we have a trailing space that we need to get rid of */
/* FIXME: check if it has to be done in lexer rather than here */
for (sz = strlen(ptr + 1); sz >= 1 && ptr[sz] == ' '; sz--) ptr[sz] = '\0';
MACRO_JumpHash(tmp, ptr + 1, HLPFILE_Hash(topic_id));
HeapFree(GetProcessHeap(), 0, tmp);
free(tmp);
}
}
else
......@@ -779,10 +771,10 @@ static void CALLBACK MACRO_RegisterRoutine(LPCSTR dll_name, LPCSTR proc, LPCSTR
/* FIXME: internationalisation for error messages */
WINE_FIXME("Cannot find dll %s\n", debugstr_a(dll_name));
}
else if ((dll = HeapAlloc(GetProcessHeap(), 0, sizeof(*dll))))
else if ((dll = malloc(sizeof(*dll))))
{
dll->hLib = hLib;
dll->name = StrDup(dll_name); /* FIXME: never freed */
dll->name = strdup(dll_name); /* FIXME: never freed */
dll->next = Globals.dlls;
Globals.dlls = dll;
dll->handler = (WINHELP_LDLLHandler)GetProcAddress(dll->hLib, "LDLLHandler");
......@@ -800,12 +792,11 @@ static void CALLBACK MACRO_RegisterRoutine(LPCSTR dll_name, LPCSTR proc, LPCSTR
}
size = ++MACRO_NumLoaded * sizeof(struct MacroDesc);
if (!MACRO_Loaded) MACRO_Loaded = HeapAlloc(GetProcessHeap(), 0, size);
else MACRO_Loaded = HeapReAlloc(GetProcessHeap(), 0, MACRO_Loaded, size);
MACRO_Loaded[MACRO_NumLoaded - 1].name = StrDup(proc); /* FIXME: never freed */
MACRO_Loaded = realloc(MACRO_Loaded, size);
MACRO_Loaded[MACRO_NumLoaded - 1].name = strdup(proc); /* FIXME: never freed */
MACRO_Loaded[MACRO_NumLoaded - 1].alias = NULL;
MACRO_Loaded[MACRO_NumLoaded - 1].isBool = FALSE;
MACRO_Loaded[MACRO_NumLoaded - 1].arguments = StrDup(args); /* FIXME: never freed */
MACRO_Loaded[MACRO_NumLoaded - 1].arguments = strdup(args); /* FIXME: never freed */
MACRO_Loaded[MACRO_NumLoaded - 1].fn = fn;
WINE_TRACE("Added %s(%s) at %p\n", debugstr_a(proc), debugstr_a(args), fn);
}
......@@ -841,10 +832,8 @@ static void CALLBACK MACRO_SetHelpOnFile(LPCSTR str)
WINE_TRACE("(%s)\n", debugstr_a(str));
HeapFree(GetProcessHeap(), 0, page->file->help_on_file);
page->file->help_on_file = HeapAlloc(GetProcessHeap(), 0, strlen(str) + 1);
if (page->file->help_on_file)
strcpy(page->file->help_on_file, str);
free(page->file->help_on_file);
page->file->help_on_file = strdup(str);
}
static void CALLBACK MACRO_SetPopupColor(LONG r, LONG g, LONG b)
......
......@@ -75,7 +75,7 @@ struct lexret yylval;
if (lex_data->quote_stk_idx == 0)
{
assert(lex_data->cache_used < ARRAY_SIZE(lex_data->cache_string));
lex_data->strptr = lex_data->cache_string[lex_data->cache_used] = HeapAlloc(GetProcessHeap(), 0, strlen(lex_data->macroptr) + 1);
lex_data->strptr = lex_data->cache_string[lex_data->cache_used] = malloc(strlen(lex_data->macroptr) + 1);
yylval.string = lex_data->strptr;
lex_data->cache_used++;
BEGIN(quote);
......@@ -355,7 +355,7 @@ BOOL MACRO_ExecuteMacro(WINHELP_WINDOW* window, LPCSTR macro)
done:
for (t = 0; t < lex_data->cache_used; t++)
HeapFree(GetProcessHeap(), 0, lex_data->cache_string[t]);
free(lex_data->cache_string[t]);
lex_data = prev_lex_data;
WINHELP_ReleaseWindow(window);
......
......@@ -129,7 +129,7 @@ static void WINHELP_SetupText(HWND hTextWnd, WINHELP_WINDOW* win, ULONG relative
cp = rd.char_pos_rel;
}
/* FIXME: else leaking potentially the rd.first_link chain */
HeapFree(GetProcessHeap(), 0, rd.data);
free(rd.data);
SendMessageW(hTextWnd, EM_POSFROMCHAR, (WPARAM)&ptl, cp ? cp - 1 : 0);
pt.x = 0; pt.y = ptl.y;
SendMessageW(hTextWnd, EM_SETSCROLLPOS, 0, (LPARAM)&pt);
......@@ -468,7 +468,7 @@ static void WINHELP_DeleteButtons(WINHELP_WINDOW* win)
{
DestroyWindow(b->hWnd);
bp = b->next;
HeapFree(GetProcessHeap(), 0, b);
free(b);
}
win->first_button = NULL;
}
......@@ -501,7 +501,7 @@ static void WINHELP_DeletePageLinks(HLPFILE_PAGE* page)
for (curr = page->first_link; curr; curr = next)
{
next = curr->next;
HeapFree(GetProcessHeap(), 0, curr);
free(curr);
}
}
......@@ -575,7 +575,7 @@ static void WINHELP_DeleteWindow(WINHELP_WINDOW* win)
WINHELP_DeleteBackSet(win);
if (win->page) HLPFILE_FreeHlpFile(win->page->file);
HeapFree(GetProcessHeap(), 0, win);
free(win);
if (bExit) MACRO_Exit();
if (!Globals.win_list)
......@@ -762,7 +762,7 @@ BOOL WINHELP_CreateHelpWindow(WINHELP_WNDPAGE* wpage, int nCmdShow, BOOL remembe
if (!win)
{
/* Initialize WINHELP_WINDOW struct */
win = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINHELP_WINDOW));
win = calloc(1, sizeof(WINHELP_WINDOW));
if (!win) return FALSE;
win->next = Globals.win_list;
Globals.win_list = win;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment