-
Notifications
You must be signed in to change notification settings - Fork 781
Open
Description
一个简单程序,初始时打开home_page页面,通过home_page页面加入sonar_single页面,sonar_single页面有一个mutable_image, 进程通过共享内存接收来自另一个进程的图片,转换成bitmap,拷贝到mutable_image上。
top发现进程的RES会增长,然后valgrind一查,发现bitmap_init这边会创建缓存,退出的时候好像这些缓存没收回去。
这个属于bitmap的用法问题还是awtk api的问题?
代码:
#include "awtk.h"
#include "../common/navigator.h"
#include "blend/image_g2d.h"
#include "ui_mqtt.h"
#include "libSharedMemory.h"
#include "libSonarSharedMemory.h"
#include "libFramebuffer.h"
static ret_t on_home_page_destroy(void* ctx, event_t* e) {
// TODO: 在此添加控件事件处理程序代码
return RET_OK;
}
static ret_t visit_init_child(void* ctx, const void* iter) {
widget_t* win = WIDGET(ctx);
widget_t* widget = WIDGET(iter);
const char* name = widget->name;
// 初始化指定名称的控件(设置属性或注册事件),请保证控件名称在窗口上唯一
if (name != NULL && *name != '\0') {
if (tk_str_eq(name, "home_page")) {
widget_on(widget, EVT_DESTROY, on_home_page_destroy, win);
}
}
return RET_OK;
}
static ret_t copy_sonarimg_to_image(void* ctx, bitmap_t* image) {
rect_t r = rect_init(0, 0, image->w, image->h);
ui_mqtt_message_t *ui_mqtt_message = ui_mqtt_get_message();
if(!ui_mqtt_message->msg_ready)
return RET_OK;
ui_mqtt_message->msg_ready = false;
if(!libSonarSharedMemoryIsReady(ui_mqtt_message->channel)){
return RET_OK;
}
char *shared_data = libSonarSharedMemoryGetData(ui_mqtt_message->channel);
bitmap_t temp_bmp;
bitmap_init(&temp_bmp, ui_mqtt_message->width, ui_mqtt_message->height, BITMAP_FMT_BGRA8888, shared_data);
image_copy(image, &temp_bmp, &r, 0, 0);
libSonarSharedMemorySetReady(ui_mqtt_message->channel, false);
return RET_OK;
}
/**
* 初始化窗口
*/
ret_t sonar_single_init(widget_t* win, void* ctx) {
(void)ctx;
return_value_if_fail(win != NULL, RET_BAD_PARAMS);
widget_foreach(win, visit_init_child, win);
widget_t *mimg0_widget = widget_lookup(win, "mimg0", TRUE);
mutable_image_set_prepare_image(mimg0_widget, copy_sonarimg_to_image, NULL);
return RET_OK;
}
日志:
valgrind --tool=memcheck --leak-check=full --show-leak-kinds=definite ./bin/test_ui
==329024== Memcheck, a memory error detector
==329024== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==329024== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==329024== Command: ./bin/test_ui
==329024==
app_root=./res
==329024== Thread 2 SDLHotplugALSA:
==329024== Conditional jump or move depends on uninitialised value(s)
==329024== at 0x8D88565: pa_shm_cleanup (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-13.99.so)
==329024== by 0x8D887A1: pa_shm_create_rw (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-13.99.so)
==329024== by 0x8D784B6: pa_mempool_new (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-13.99.so)
==329024== by 0x8CFD9B1: pa_context_new_with_proplist (in /usr/lib/x86_64-linux-gnu/libpulse.so.0.21.2)
==329024== by 0x484B2B6: conf_pulse_hook_load_if_running (in /usr/lib/x86_64-linux-gnu/alsa-lib/libasound_module_conf_pulse.so)
==329024== by 0x64510DD: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==329024== by 0x6451544: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==329024== by 0x6451F21: snd_config_searcha_hooks (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==329024== by 0x6452010: snd_config_searchva_hooks (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==329024== by 0x645211A: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==329024== by 0x64508F5: snd_config_search_definition (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==329024== by 0x6458212: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==329024==
WITH_FB_BGRA8888
Build at: Nov 28 2024 19:35:40
key 1231 len 1536008
key 1232 len 1536008
key 1233 len 1536008
key 1234 len 1536008
Connection topic: sonar
Window 1 shown
Window 1 hidden
Window 1 shown
Window 1 moved to 408,280
Window 1 exposed
Mouse entered window 1
Window 1 gained keyboard focus
Window 1 is offered a focus
window home_page open
try font load default_zh_CN
try font load default_zh
load asset default
ui send: ui hello
Mouse left window 1
Mouse entered window 1
Mouse left window 1
Mouse entered window 1
window sonar_single open
==329024== Thread 1:
==329024== Conditional jump or move depends on uninitialised value(s)
==329024== at 0x4A706C5: bitmap_init (bitmap.c:584)
==329024== by 0x10CDE4: copy_sonarimg_to_image (sonar_single.c:49)
==329024== by 0x4A0328C: mutable_image_prepare_image (mutable_image.c:66)
==329024== by 0x4A03405: mutable_image_on_paint_self (mutable_image.c:83)
==329024== by 0x4ADA67B: widget_vtable_on_paint_self (widget_vtable.c:251)
==329024== by 0x4AC8F1D: widget_on_paint_self (widget.c:2523)
==329024== by 0x4AC58A5: widget_paint_impl (widget.c:1840)
==329024== by 0x4AC5A31: widget_paint (widget.c:1868)
==329024== by 0x4ADDAA3: widget_on_paint_children_default (widget_vtable.c:752)
==329024== by 0x4AC909C: widget_on_paint_children (widget.c:2539)
==329024== by 0x4AC58B8: widget_paint_impl (widget.c:1841)
==329024== by 0x4AC5A31: widget_paint (widget.c:1868)
==329024==
Mouse left window 1
Window 1 is offered a focus
Window 1 is offered a focus
Window 1 moved to 498,279
Window 1 moved to 533,268
Mouse entered window 1
EVT_REQUEST_CLOSE_WINDOW
Mouse left window 1
Window 1 lost keyboard focus
Mouse entered window 1
Mouse left window 1
Mouse entered window 1
Mouse left window 1
Mouse entered window 1
Window 1 gained keyboard focus
Window 1 is offered a focus
Mouse left window 1
Mouse entered window 1
Mouse left window 1
Window 1 got unknown event 14
application_exit
Close native window.
==329024==
==329024== HEAP SUMMARY:
==329024== in use at exit: 401,352 bytes in 5,253 blocks
==329024== total heap usage: 603,263 allocs, 598,010 frees, 118,577,913 bytes allocated
==329024==
==329024== 18 bytes in 1 blocks are definitely lost in loss record 127 of 2,864
==329024== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==329024== by 0x632A896: _XlcDefaultMapModifiers (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==329024== by 0x632AC6A: XSetLocaleModifiers (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==329024== by 0x4F3C7B7: X11_InitKeyboard (SDL_x11keyboard.c:321)
==329024== by 0x4DDB337: X11_VideoInit (SDL_x11video.c:448)
==329024== by 0x4DC1F1B: SDL_VideoInit (SDL_video.c:532)
==329024== by 0x4D8F7DF: SDL_InitSubSystem (SDL.c:171)
==329024== by 0x4D8F8CD: SDL_Init (SDL.c:256)
==329024== by 0x4B83249: native_window_sdl_init (native_window_sdl.c:657)
==329024== by 0x4B8717A: main_loop_init (main_loop_sdl.c:372)
==329024== by 0x49DE586: tk_init (awtk_global.c:341)
==329024== by 0x10D448: main (awtk_main.inc:190)
==329024==
==329024== 64 bytes in 1 blocks are definitely lost in loss record 2,366 of 2,864
==329024== at 0x483BE63: operator new(unsigned long) (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==329024== by 0xA0500CD: ???
==329024== by 0x97E1063: ???
==329024== by 0x4011B99: call_init.part.0 (dl-init.c:72)
==329024== by 0x4011CA0: call_init (dl-init.c:30)
==329024== by 0x4011CA0: _dl_init (dl-init.c:119)
==329024== by 0x5476BA4: _dl_catch_exception (dl-error-skeleton.c:182)
==329024== by 0x401643C: dl_open_worker (dl-open.c:758)
==329024== by 0x5476B47: _dl_catch_exception (dl-error-skeleton.c:208)
==329024== by 0x4015609: _dl_open (dl-open.c:837)
==329024== by 0x666A34B: dlopen_doit (dlopen.c:66)
==329024== by 0x5476B47: _dl_catch_exception (dl-error-skeleton.c:208)
==329024== by 0x5476C12: _dl_catch_error (dl-error-skeleton.c:227)
==329024==
==329024== 112 (56 direct, 56 indirect) bytes in 1 blocks are definitely lost in loss record 2,722 of 2,864
==329024== at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==329024== by 0xA3B78EE: ???
==329024== by 0x9ED379B: ???
==329024== by 0x9EBDDC5: ???
==329024== by 0x9EBDFA4: ???
==329024== by 0x9E6B5CF: ???
==329024== by 0x9E6E10C: ???
==329024== by 0x9E68F2C: ???
==329024== by 0x9E0D5C7: ???
==329024== by 0x9E4EE7D: ???
==329024== by 0x9E4BBDE: ???
==329024== by 0x9DDECE5: ???
==329024==
==329024== 560 bytes in 14 blocks are definitely lost in loss record 2,792 of 2,864
==329024== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==329024== by 0x4C5EE32: mem_allocator_std_alloc (mem_allocator_std.h:78)
==329024== by 0x4C5DC27: mem_allocator_alloc (mem_allocator.h:74)
==329024== by 0x4C5E02E: mem_allocator_oom_alloc (mem_allocator_oom.h:77)
==329024== by 0x4C5DC27: mem_allocator_alloc (mem_allocator.h:74)
==329024== by 0x4C5F263: tk_calloc (mem.c:158)
==329024== by 0x4B8190B: graphic_buffer_create_with_data (graphic_buffer_default.c:169)
==329024== by 0x4A7082C: bitmap_init_ex (bitmap.c:611)
==329024== by 0x4A70716: bitmap_init (bitmap.c:590)
==329024== by 0x10CDE4: copy_sonarimg_to_image (sonar_single.c:49)
==329024== by 0x4A0328C: mutable_image_prepare_image (mutable_image.c:66)
==329024== by 0x4A03405: mutable_image_on_paint_self (mutable_image.c:83)
==329024==
==329024== 5,355 bytes in 255 blocks are definitely lost in loss record 2,857 of 2,864
==329024== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==329024== by 0x53B538E: strdup (strdup.c:42)
==329024== by 0x93BD6F6: ???
==329024== by 0x93BD4A4: ???
==329024== by 0x927E436: ??? (in /usr/lib/x86_64-linux-gnu/libGLdispatch.so.0.0.0)
==329024== by 0x927EE1C: __glDispatchMakeCurrent (in /usr/lib/x86_64-linux-gnu/libGLdispatch.so.0.0.0)
==329024== by 0x92FA419: ??? (in /usr/lib/x86_64-linux-gnu/libGLX.so.0.0.0)
==329024== by 0x92FBC57: ??? (in /usr/lib/x86_64-linux-gnu/libGLX.so.0.0.0)
==329024== by 0x4F3F817: X11_GL_InitExtensions (SDL_x11opengl.c:369)
==329024== by 0x4F3F2F5: X11_GL_LoadLibrary (SDL_x11opengl.c:235)
==329024== by 0x4DC979F: SDL_GL_LoadLibrary (SDL_video.c:2898)
==329024== by 0x4DC5266: SDL_RecreateWindow (SDL_video.c:1667)
==329024==
==329024== LEAK SUMMARY:
==329024== definitely lost: 6,053 bytes in 272 blocks
==329024== indirectly lost: 56 bytes in 1 blocks
==329024== possibly lost: 67,588 bytes in 1,813 blocks
==329024== still reachable: 327,655 bytes in 3,167 blocks
==329024== of which reachable via heuristic:
==329024== newarray : 1,536 bytes in 16 blocks
==329024== suppressed: 0 bytes in 0 blocks
==329024== Reachable blocks (those to which a pointer was found) are not shown.
==329024== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==329024==
==329024== Use --track-origins=yes to see where uninitialised values come from
==329024== For lists of detected and suppressed errors, rerun with: -s
==329024== ERROR SUMMARY: 142 errors from 119 contexts (suppressed: 2 from 2)
Metadata
Metadata
Assignees
Labels
No labels