From 6cb7bf1eb6fd90d64cfe8f900d7457abaf6d61b4 Mon Sep 17 00:00:00 2001 From: "Kirill Lipatov (Leency)" Date: Wed, 16 Dec 2020 16:30:39 +0000 Subject: [PATCH] WebView: fixed memory leak in cache.add(), give system memory back each time parse ends git-svn-id: svn://kolibrios.org@8425 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/cmm/browser/TWB/TWB.c | 5 +++++ programs/cmm/browser/WebView.c | 6 ++++-- programs/cmm/browser/cache.h | 3 +++ programs/cmm/downloader/dl.c | 1 - programs/cmm/lib/draw_buf.h | 19 +++++++------------ programs/cmm/sysmon/sysmon.c | 2 -- 6 files changed, 19 insertions(+), 17 deletions(-) diff --git a/programs/cmm/browser/TWB/TWB.c b/programs/cmm/browser/TWB/TWB.c index 17a65fa884..6b7254b39f 100644 --- a/programs/cmm/browser/TWB/TWB.c +++ b/programs/cmm/browser/TWB/TWB.c @@ -304,6 +304,11 @@ void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){ Paint(); NewLine(); list.count = draw_y; + + DrawBuf.bufh = math.max(list.visible, draw_y); + debugval("DrawBuf.bufh", DrawBuf.bufh); + buf_data = realloc(buf_data, DrawBuf.bufh * DrawBuf.bufw * 4 + 8); + list.CheckDoesValuesOkey(); anchors.current = NULL; custom_encoding = -1; diff --git a/programs/cmm/browser/WebView.c b/programs/cmm/browser/WebView.c index f9847e235c..bff5883ff7 100644 --- a/programs/cmm/browser/WebView.c +++ b/programs/cmm/browser/WebView.c @@ -41,7 +41,7 @@ // DATA // // // //===================================================// -char version[]="WebView 3.04"; +char version[]="WebView 3.06"; #define DEFAULT_URL URL_SERVICE_HOMEPAGE @@ -231,10 +231,12 @@ void main() if (http_get_type==PAGE) { history.add(http.cur_url); cache.add(http.cur_url, http.content_pointer, http.content_received, PAGE); - LoadInternalPage(http.content_pointer, http.content_received); + free(http.content_pointer); + LoadInternalPage(cache.current_buf, cache.current_size); } else if (http_get_type==IMG) { cache.add(cur_img_url, http.content_pointer, http.content_received, IMG); + free(http.content_pointer); GetImg(false); } } diff --git a/programs/cmm/browser/cache.h b/programs/cmm/browser/cache.h index fd118f28d7..d4d0a53958 100644 --- a/programs/cmm/browser/cache.h +++ b/programs/cmm/browser/cache.h @@ -26,6 +26,9 @@ void _cache::add(dword _url, _data, _size, _type) url.add(_url); size.add(_size); type.add(_type); + + current_buf = data_pointer; + current_size = _size; } bool _cache::has(dword _link) diff --git a/programs/cmm/downloader/dl.c b/programs/cmm/downloader/dl.c index 25d9c1115f..f87e55be43 100644 --- a/programs/cmm/downloader/dl.c +++ b/programs/cmm/downloader/dl.c @@ -54,7 +54,6 @@ void main() } @SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK); - @SetWindowLayerBehaviour(-1, ZPOS_ALWAYS_TOP); loop() switch(@WaitEvent()) { case evMouse: edit_box_mouse stdcall (#ed); break; diff --git a/programs/cmm/lib/draw_buf.h b/programs/cmm/lib/draw_buf.h index 946708179a..c6aaf2405a 100644 --- a/programs/cmm/lib/draw_buf.h +++ b/programs/cmm/lib/draw_buf.h @@ -128,26 +128,22 @@ void DrawBufer::Show(dword _y_offset, _h) void DrawBufer::IncreaseBufSize() { - static dword alloc_counter; static dword bufh_initial; dword alloc_size; dword free_ram_size; char error_str[256]; if (!buf_data) { - alloc_counter = 1; - bufh_initial = bufh; - alloc_size = bufw * bufh * 4 + 8; + alloc_size = bufh * bufw * 4 + 8; buf_data = malloc(alloc_size); - } - else { - alloc_counter++; - bufh = bufh_initial * alloc_counter; - alloc_size = bufw * bufh * 4 + 8; + } else { + if (bufh_initial != bufh) bufh_initial = bufh; + bufh += 4096*1600/bufw; //+50 Mb + alloc_size = bufh * bufw * 4 + 8; buf_data = realloc(buf_data, alloc_size); - Fill(alloc_counter - 1 * bufw * bufh_initial * 4 + 8, fill_color); + Fill(bufh_initial * bufw * 4 + 8, fill_color); } - + bufh_initial = bufh; free_ram_size = GetFreeRAM() * 1024; if (alloc_size > free_ram_size) { sprintf(#error_str, #draw_buf_not_enaught_ram, alloc_size - free_ram_size/1048576); @@ -156,5 +152,4 @@ void DrawBufer::IncreaseBufSize() } - #endif \ No newline at end of file diff --git a/programs/cmm/sysmon/sysmon.c b/programs/cmm/sysmon/sysmon.c index 949681f45f..5fdebdd3c9 100644 --- a/programs/cmm/sysmon/sysmon.c +++ b/programs/cmm/sysmon/sysmon.c @@ -106,9 +106,7 @@ void load_lib() void main() { int btn; - //dword cpu_frequency = GetCpuFrequency()/1000; load_lib(); - @SetWindowLayerBehaviour(-1, ZPOS_ALWAYS_TOP); @SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER); loop() switch(@WaitEventTimeout(50)) {