From: Alex Henrie alexhenrie24@gmail.com
--- programs/winhlp32/hlpfile.c | 140 ++++++++++++++++------------------ programs/winhlp32/macro.c | 35 +++------ programs/winhlp32/macro.lex.l | 4 +- programs/winhlp32/winhelp.c | 10 +-- 4 files changed, 85 insertions(+), 104 deletions(-)
diff --git a/programs/winhlp32/hlpfile.c b/programs/winhlp32/hlpfile.c index 73c4f4a27af..e8ae723cff0 100644 --- a/programs/winhlp32/hlpfile.c +++ b/programs/winhlp32/hlpfile.c @@ -22,6 +22,7 @@
#include <stdarg.h> #include <stdio.h> +#include <stdlib.h> #include <string.h>
#include "windef.h" @@ -655,13 +656,13 @@ static const BYTE* HLPFILE_DecompressGfx(const BYTE* src, unsigned csz, uns *alloc = NULL; break; case 1: /* RunLen */ - dst = *alloc = HeapAlloc(GetProcessHeap(), 0, sz); + dst = *alloc = malloc(sz); if (!dst) return NULL; HLPFILE_UncompressRLE(src, src + csz, *alloc, sz); break; case 2: /* LZ77 */ sz77 = HLPFILE_UncompressedLZ77_Size(src, src + csz); - dst = *alloc = HeapAlloc(GetProcessHeap(), 0, sz77); + dst = *alloc = malloc(sz77); if (!dst) return NULL; HLPFILE_UncompressLZ77(src, src + csz, *alloc); if (sz77 != sz) @@ -669,17 +670,17 @@ static const BYTE* HLPFILE_DecompressGfx(const BYTE* src, unsigned csz, uns break; case 3: /* LZ77 then RLE */ sz77 = HLPFILE_UncompressedLZ77_Size(src, src + csz); - tmp = HeapAlloc(GetProcessHeap(), 0, sz77); + tmp = malloc(sz77); if (!tmp) return FALSE; HLPFILE_UncompressLZ77(src, src + csz, tmp); - dst = *alloc = HeapAlloc(GetProcessHeap(), 0, sz); + dst = *alloc = malloc(sz); if (!dst) { - HeapFree(GetProcessHeap(), 0, tmp); + free(tmp); return FALSE; } HLPFILE_UncompressRLE(tmp, tmp + sz77, *alloc, sz); - HeapFree(GetProcessHeap(), 0, tmp); + free(tmp); break; default: WINE_FIXME("Unsupported packing %u\n", packing); @@ -692,10 +693,11 @@ static BOOL HLPFILE_RtfAddRawString(struct RtfData* rd, const char* str, size_t { if (rd->ptr + sz >= rd->data + rd->allocated) { - char* new = HeapReAlloc(GetProcessHeap(), 0, rd->data, rd->allocated *= 2); + char* new = realloc(rd->data, rd->allocated * 2); if (!new) return FALSE; rd->ptr = new + (rd->ptr - rd->data); rd->data = new; + rd->allocated *= 2; } memcpy(rd->ptr, str, sz); rd->ptr += sz; @@ -844,7 +846,7 @@ static void HLPFILE_AddHotSpotLinks(struct RtfData* rd, HLPFILE* file, } if (wnd == -1) WINE_WARN("Couldn't find window info for %s\n", debugstr_a(win)); - if ((tgt = HeapAlloc(GetProcessHeap(), 0, win - str + 1))) + if ((tgt = malloc(win - str + 1))) { memcpy(tgt, str, win - str); tgt[win - str] = '\0'; @@ -853,7 +855,7 @@ static void HLPFILE_AddHotSpotLinks(struct RtfData* rd, HLPFILE* file, hslink = (HLPFILE_HOTSPOTLINK*) HLPFILE_AllocLink(rd, (start[7 + 15 * i + 0] & 1) ? hlp_link_link : hlp_link_popup, file->lpszPath, -1, HLPFILE_Hash(tgt ? tgt : str), FALSE, TRUE, wnd); - HeapFree(GetProcessHeap(), 0, tgt); + free(tgt); break; } default: @@ -939,7 +941,7 @@ static BOOL HLPFILE_RtfAddTransparentBitmap(struct RtfData* rd, const BITMAPINFO
/* generate rtf stream */ sz = GetEnhMetaFileBits(hEMF, 0, NULL); - if (sz && (data = HeapAlloc(GetProcessHeap(), 0, sz))) + if (sz && (data = malloc(sz))) { if (sz == GetEnhMetaFileBits(hEMF, sz, data)) { @@ -947,7 +949,7 @@ static BOOL HLPFILE_RtfAddTransparentBitmap(struct RtfData* rd, const BITMAPINFO HLPFILE_RtfAddHexBytes(rd, data, sz) && HLPFILE_RtfAddControl(rd, "}"); } - HeapFree(GetProcessHeap(), 0, data); + free(data); } DeleteEnhMetaFile(hEMF);
@@ -971,7 +973,7 @@ static BOOL HLPFILE_RtfAddBitmap(struct RtfData* rd, HLPFILE* file, const BYTE* char tmp[256]; unsigned hs_size, hs_offset;
- bi = HeapAlloc(GetProcessHeap(), 0, sizeof(*bi)); + bi = malloc(sizeof(*bi)); if (!bi) return FALSE;
ptr = beg + 2; /* for type and pack */ @@ -1011,7 +1013,7 @@ static BOOL HLPFILE_RtfAddBitmap(struct RtfData* rd, HLPFILE* file, const BYTE* if (!nc && bi->bmiHeader.biBitCount <= 8) nc = 1 << bi->bmiHeader.biBitCount;
- bi = HeapReAlloc(GetProcessHeap(), 0, bi, sizeof(*bi) + nc * sizeof(RGBQUAD)); + bi = realloc(bi, sizeof(*bi) + nc * sizeof(RGBQUAD)); if (!bi) return FALSE; for (i = 0; i < nc; i++) { @@ -1049,8 +1051,8 @@ static BOOL HLPFILE_RtfAddBitmap(struct RtfData* rd, HLPFILE* file, const BYTE*
ret = TRUE; done: - HeapFree(GetProcessHeap(), 0, bi); - HeapFree(GetProcessHeap(), 0, alloc); + free(bi); + free(alloc);
return ret; } @@ -1097,7 +1099,7 @@ static BOOL HLPFILE_RtfAddMetaFile(struct RtfData* rd, HLPFILE* file, const ret = HLPFILE_RtfAddHexBytes(rd, bits, size) && HLPFILE_RtfAddControl(rd, "}");
- HeapFree(GetProcessHeap(), 0, alloc); + free(alloc);
return ret; } @@ -1185,7 +1187,7 @@ static HLPFILE_LINK* HLPFILE_AllocLink(struct RtfData* rd, int cookie, * they are reallocated for each link */ if (len == -1) len = strlen(str); - link = HeapAlloc(GetProcessHeap(), 0, asz + len + 1); + link = malloc(asz + len + 1); if (!link) return NULL;
link->cookie = cookie; @@ -1239,7 +1241,7 @@ static BOOL HLPFILE_BrowseParagraph(HLPFILE_PAGE* page, struct RtfData* rd, blocksize = GET_UINT(buf, 0); size = GET_UINT(buf, 0x4); datalen = GET_UINT(buf, 0x10); - text = text_base = HeapAlloc(GetProcessHeap(), 0, size); + text = text_base = malloc(size); if (!text) return FALSE; if (size > blocksize - datalen) { @@ -1692,7 +1694,7 @@ static BOOL HLPFILE_BrowseParagraph(HLPFILE_PAGE* page, struct RtfData* rd, ret = TRUE; done:
- HeapFree(GetProcessHeap(), 0, text_base); + free(text_base); return ret; }
@@ -1712,7 +1714,7 @@ BOOL HLPFILE_BrowsePage(HLPFILE_PAGE* page, struct RtfData* rd, const char* ck = NULL;
rd->in_text = TRUE; - rd->data = rd->ptr = HeapAlloc(GetProcessHeap(), 0, rd->allocated = 32768); + rd->data = rd->ptr = malloc(rd->allocated = 32768); rd->char_pos = 0; rd->first_link = rd->current_link = NULL; rd->force_color = FALSE; @@ -1875,7 +1877,7 @@ static BOOL HLPFILE_ReadFont(HLPFILE* hlpfile) face_num, face_offset, dscr_num, dscr_offset);
hlpfile->numFonts = dscr_num; - hlpfile->fonts = HeapAlloc(GetProcessHeap(), 0, sizeof(HLPFILE_FONT) * dscr_num); + hlpfile->fonts = malloc(sizeof(HLPFILE_FONT) * dscr_num);
len = (dscr_offset - face_offset) / face_num;
@@ -1976,7 +1978,7 @@ static BOOL HLPFILE_ReadFileToBuffer(HLPFILE* hlpfile, HFILE hFile) {WINE_WARN("wrong header\n"); return FALSE;};
hlpfile->file_buffer_size = GET_UINT(header, 12); - hlpfile->file_buffer = HeapAlloc(GetProcessHeap(), 0, hlpfile->file_buffer_size + 1); + hlpfile->file_buffer = malloc(hlpfile->file_buffer_size + 1); if (!hlpfile->file_buffer) return FALSE;
memcpy(hlpfile->file_buffer, header, 16); @@ -2048,9 +2050,8 @@ static BOOL HLPFILE_SystemCommands(HLPFILE* hlpfile) { char *str = (char*)buf + 0x15;
- hlpfile->lpszTitle = HeapAlloc(GetProcessHeap(), 0, strlen(str) + 1); + hlpfile->lpszTitle = strdup(str); if (!hlpfile->lpszTitle) return FALSE; - strcpy(hlpfile->lpszTitle, str); WINE_TRACE("Title: %s\n", debugstr_a(hlpfile->lpszTitle)); /* Nothing more to parse */ return TRUE; @@ -2062,17 +2063,15 @@ static BOOL HLPFILE_SystemCommands(HLPFILE* hlpfile) { case 1: if (hlpfile->lpszTitle) {WINE_WARN("title\n"); break;} - hlpfile->lpszTitle = HeapAlloc(GetProcessHeap(), 0, strlen(str) + 1); + hlpfile->lpszTitle = strdup(str); if (!hlpfile->lpszTitle) return FALSE; - strcpy(hlpfile->lpszTitle, str); WINE_TRACE("Title: %s\n", debugstr_a(hlpfile->lpszTitle)); break;
case 2: if (hlpfile->lpszCopyright) {WINE_WARN("copyright\n"); break;} - hlpfile->lpszCopyright = HeapAlloc(GetProcessHeap(), 0, strlen(str) + 1); + hlpfile->lpszCopyright = strdup(str); if (!hlpfile->lpszCopyright) return FALSE; - strcpy(hlpfile->lpszCopyright, str); WINE_TRACE("Copyright: %s\n", debugstr_a(hlpfile->lpszCopyright)); break;
@@ -2083,7 +2082,7 @@ static BOOL HLPFILE_SystemCommands(HLPFILE* hlpfile) break;
case 4: - macro = HeapAlloc(GetProcessHeap(), 0, sizeof(HLPFILE_MACRO) + strlen(str) + 1); + macro = malloc(sizeof(HLPFILE_MACRO) + strlen(str) + 1); if (!macro) break; p = (char*)macro + sizeof(HLPFILE_MACRO); strcpy(p, str); @@ -2105,13 +2104,9 @@ static BOOL HLPFILE_SystemCommands(HLPFILE* hlpfile) case 6: if (GET_USHORT(ptr, 2) != 90) {WINE_WARN("system6\n");break;}
- if (hlpfile->windows) - hlpfile->windows = HeapReAlloc(GetProcessHeap(), 0, hlpfile->windows, + hlpfile->windows = realloc(hlpfile->windows, sizeof(HLPFILE_WINDOWINFO) * ++hlpfile->numWindows); - else - hlpfile->windows = HeapAlloc(GetProcessHeap(), 0, - sizeof(HLPFILE_WINDOWINFO) * ++hlpfile->numWindows); - + if (hlpfile->windows) { HLPFILE_WINDOWINFO* wi = &hlpfile->windows[hlpfile->numWindows - 1]; @@ -2156,7 +2151,7 @@ static BOOL HLPFILE_SystemCommands(HLPFILE* hlpfile) } } if (!hlpfile->lpszTitle) - hlpfile->lpszTitle = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 1); + hlpfile->lpszTitle = strdup(""); return TRUE; }
@@ -2173,7 +2168,7 @@ static BOOL HLPFILE_GetContext(HLPFILE *hlpfile) {WINE_WARN("context0\n"); return FALSE;}
clen = cend - cbuf; - hlpfile->Context = HeapAlloc(GetProcessHeap(), 0, clen); + hlpfile->Context = malloc(clen); if (!hlpfile->Context) return FALSE; memcpy(hlpfile->Context, cbuf, clen);
@@ -2191,21 +2186,21 @@ static BOOL HLPFILE_GetKeywords(HLPFILE *hlpfile)
if (!HLPFILE_FindSubFile(hlpfile, "|KWBTREE", &cbuf, &cend)) return FALSE; clen = cend - cbuf; - hlpfile->kwbtree = HeapAlloc(GetProcessHeap(), 0, clen); + hlpfile->kwbtree = malloc(clen); if (!hlpfile->kwbtree) return FALSE; memcpy(hlpfile->kwbtree, cbuf, clen);
if (!HLPFILE_FindSubFile(hlpfile, "|KWDATA", &cbuf, &cend)) { WINE_ERR("corrupted help file: kwbtree present but kwdata absent\n"); - HeapFree(GetProcessHeap(), 0, hlpfile->kwbtree); + free(hlpfile->kwbtree); return FALSE; } clen = cend - cbuf; - hlpfile->kwdata = HeapAlloc(GetProcessHeap(), 0, clen); + hlpfile->kwdata = malloc(clen); if (!hlpfile->kwdata) { - HeapFree(GetProcessHeap(), 0, hlpfile->kwdata); + free(hlpfile->kwdata); return FALSE; } memcpy(hlpfile->kwdata, cbuf, clen); @@ -2226,7 +2221,7 @@ static BOOL HLPFILE_GetMap(HLPFILE *hlpfile) {WINE_WARN("no map section\n"); return FALSE;}
entries = GET_USHORT(cbuf, 9); - hlpfile->Map = HeapAlloc(GetProcessHeap(), 0, entries * sizeof(HLPFILE_MAP)); + hlpfile->Map = malloc(entries * sizeof(HLPFILE_MAP)); if (!hlpfile->Map) return FALSE; hlpfile->wMapLen = entries; for (i = 0; i < entries; i++) @@ -2250,7 +2245,7 @@ static BOOL HLPFILE_GetTOMap(HLPFILE *hlpfile) {WINE_WARN("no tomap section\n"); return FALSE;}
clen = cend - cbuf - 9; - hlpfile->TOMap = HeapAlloc(GetProcessHeap(), 0, clen); + hlpfile->TOMap = malloc(clen); if (!hlpfile->TOMap) return FALSE; memcpy(hlpfile->TOMap, cbuf+9, clen); hlpfile->wTOMapLen = clen/4; @@ -2268,7 +2263,7 @@ static void HLPFILE_DeleteMacro(HLPFILE_MACRO* macro) while (macro) { next = macro->next; - HeapFree(GetProcessHeap(), 0, macro); + free(macro); macro = next; } } @@ -2285,7 +2280,7 @@ static void HLPFILE_DeletePage(HLPFILE_PAGE* page) { next = page->next; HLPFILE_DeleteMacro(page->first_macro); - HeapFree(GetProcessHeap(), 0, page); + free(page); page = next; } } @@ -2310,7 +2305,7 @@ void HLPFILE_FreeHlpFile(HLPFILE* hlpfile) { DeleteObject(hlpfile->fonts[i].hFont); } - HeapFree(GetProcessHeap(), 0, hlpfile->fonts); + free(hlpfile->fonts); }
if (hlpfile->numBmps) @@ -2319,24 +2314,24 @@ void HLPFILE_FreeHlpFile(HLPFILE* hlpfile) { DeleteObject(hlpfile->bmps[i]); } - HeapFree(GetProcessHeap(), 0, hlpfile->bmps); + free(hlpfile->bmps); }
HLPFILE_DeletePage(hlpfile->first_page); HLPFILE_DeleteMacro(hlpfile->first_macro);
DestroyIcon(hlpfile->hIcon); - if (hlpfile->numWindows) HeapFree(GetProcessHeap(), 0, hlpfile->windows); - HeapFree(GetProcessHeap(), 0, hlpfile->Context); - HeapFree(GetProcessHeap(), 0, hlpfile->Map); - HeapFree(GetProcessHeap(), 0, hlpfile->lpszTitle); - HeapFree(GetProcessHeap(), 0, hlpfile->lpszCopyright); - HeapFree(GetProcessHeap(), 0, hlpfile->file_buffer); - HeapFree(GetProcessHeap(), 0, hlpfile->phrases_offsets); - HeapFree(GetProcessHeap(), 0, hlpfile->phrases_buffer); - HeapFree(GetProcessHeap(), 0, hlpfile->topic_map); - HeapFree(GetProcessHeap(), 0, hlpfile->help_on_file); - HeapFree(GetProcessHeap(), 0, hlpfile); + if (hlpfile->numWindows) free(hlpfile->windows); + free(hlpfile->Context); + free(hlpfile->Map); + free(hlpfile->lpszTitle); + free(hlpfile->lpszCopyright); + free(hlpfile->file_buffer); + free(hlpfile->phrases_offsets); + free(hlpfile->phrases_buffer); + free(hlpfile->topic_map); + free(hlpfile->help_on_file); + free(hlpfile); }
/*********************************************************************** @@ -2363,12 +2358,12 @@ static BOOL HLPFILE_UncompressLZ77_Phrases(HLPFILE* hlpfile) else dec_size = HLPFILE_UncompressedLZ77_Size(buf + 0x13 + 2 * num, end);
- hlpfile->phrases_offsets = HeapAlloc(GetProcessHeap(), 0, sizeof(unsigned) * (num + 1)); - hlpfile->phrases_buffer = HeapAlloc(GetProcessHeap(), 0, dec_size); + hlpfile->phrases_offsets = malloc(sizeof(unsigned) * (num + 1)); + hlpfile->phrases_buffer = malloc(dec_size); if (!hlpfile->phrases_offsets || !hlpfile->phrases_buffer) { - HeapFree(GetProcessHeap(), 0, hlpfile->phrases_offsets); - HeapFree(GetProcessHeap(), 0, hlpfile->phrases_buffer); + free(hlpfile->phrases_offsets); + free(hlpfile->phrases_buffer); return FALSE; }
@@ -2427,12 +2422,12 @@ static BOOL HLPFILE_Uncompress_Phrases40(HLPFILE* hlpfile) dec_size = max(dec_size, HLPFILE_UncompressedLZ77_Size(buf_phs + 9, end_phs)); }
- hlpfile->phrases_offsets = HeapAlloc(GetProcessHeap(), 0, sizeof(unsigned) * (num + 1)); - hlpfile->phrases_buffer = HeapAlloc(GetProcessHeap(), 0, dec_size); + hlpfile->phrases_offsets = malloc(sizeof(unsigned) * (num + 1)); + hlpfile->phrases_buffer = malloc(dec_size); if (!hlpfile->phrases_offsets || !hlpfile->phrases_buffer) { - HeapFree(GetProcessHeap(), 0, hlpfile->phrases_offsets); - HeapFree(GetProcessHeap(), 0, hlpfile->phrases_buffer); + free(hlpfile->phrases_offsets); + free(hlpfile->phrases_buffer); return FALSE; }
@@ -2490,8 +2485,7 @@ static BOOL HLPFILE_Uncompress_Topic(HLPFILE* hlpfile) newsize += HLPFILE_UncompressedLZ77_Size(ptr + 0xc, min(end, ptr + hlpfile->tbsize)); }
- hlpfile->topic_map = HeapAlloc(GetProcessHeap(), 0, - hlpfile->topic_maplen * sizeof(hlpfile->topic_map[0]) + newsize); + hlpfile->topic_map = malloc(hlpfile->topic_maplen * sizeof(hlpfile->topic_map[0]) + newsize); if (!hlpfile->topic_map) return FALSE; newptr = (BYTE*)(hlpfile->topic_map + hlpfile->topic_maplen); hlpfile->topic_end = newptr + newsize; @@ -2511,8 +2505,7 @@ static BOOL HLPFILE_Uncompress_Topic(HLPFILE* hlpfile) * (removing the first 0x0C) in one single area in memory */ hlpfile->topic_maplen = (topic_size - 1) / hlpfile->tbsize + 1; - hlpfile->topic_map = HeapAlloc(GetProcessHeap(), 0, - hlpfile->topic_maplen * (sizeof(hlpfile->topic_map[0]) + hlpfile->dsize)); + hlpfile->topic_map = malloc(hlpfile->topic_maplen * (sizeof(hlpfile->topic_map[0]) + hlpfile->dsize)); if (!hlpfile->topic_map) return FALSE; newptr = (BYTE*)(hlpfile->topic_map + hlpfile->topic_maplen); hlpfile->topic_end = newptr + topic_size; @@ -2544,7 +2537,7 @@ static BOOL HLPFILE_AddPage(HLPFILE *hlpfile, const BYTE *buf, const BYTE *end, if (title > end) {WINE_WARN("page2\n"); return FALSE;};
titlesize = GET_UINT(buf, 4); - page = HeapAlloc(GetProcessHeap(), 0, sizeof(HLPFILE_PAGE) + titlesize + 1); + page = malloc(sizeof(HLPFILE_PAGE) + titlesize + 1); if (!page) return FALSE; page->lpszTitle = (char*)page + sizeof(HLPFILE_PAGE);
@@ -2616,7 +2609,7 @@ static BOOL HLPFILE_AddPage(HLPFILE *hlpfile, const BYTE *buf, const BYTE *end, char* macro_str;
WINE_TRACE("macro: %s\n", debugstr_a(ptr)); - macro = HeapAlloc(GetProcessHeap(), 0, sizeof(HLPFILE_MACRO) + len + 1); + macro = malloc(sizeof(HLPFILE_MACRO) + len + 1); macro->lpszMacro = macro_str = (char*)(macro + 1); memcpy(macro_str, ptr, len + 1); /* FIXME: shall we really link macro in reverse order ?? @@ -2769,8 +2762,7 @@ HLPFILE *HLPFILE_ReadHlpFile(LPCSTR lpszPath) } }
- hlpfile = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, - sizeof(HLPFILE) + strlen(lpszPath) + 1); + hlpfile = calloc(1, sizeof(HLPFILE) + strlen(lpszPath) + 1); if (!hlpfile) return 0;
hlpfile->lpszPath = (char*)hlpfile + sizeof(HLPFILE); diff --git a/programs/winhlp32/macro.c b/programs/winhlp32/macro.c index 777efbbf74f..36bda654afd 100644 --- a/programs/winhlp32/macro.c +++ b/programs/winhlp32/macro.c @@ -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) diff --git a/programs/winhlp32/macro.lex.l b/programs/winhlp32/macro.lex.l index 08067a4548f..b58e446eb45 100644 --- a/programs/winhlp32/macro.lex.l +++ b/programs/winhlp32/macro.lex.l @@ -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);
diff --git a/programs/winhlp32/winhelp.c b/programs/winhlp32/winhelp.c index 73db4b58876..037d319f290 100644 --- a/programs/winhlp32/winhelp.c +++ b/programs/winhlp32/winhelp.c @@ -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;