fix memory leak

This commit is contained in:
lixianjing 2024-03-15 15:31:20 +08:00
parent 2e17221308
commit c86de8135a
4 changed files with 17 additions and 8 deletions

View File

@ -293,8 +293,7 @@ ret_t tk_object_set_prop_pointer_ex(tk_object_t* obj, const char* name, void* va
tk_destroy_t destroy) {
value_t v;
ret_t ret = RET_OK;
value_set_pointer_ex(&v, value, destroy);
value_set_int(&v, 0);
ret = tk_object_set_prop(obj, name, value_set_pointer_ex(&v, value, destroy));
value_reset(&v);

View File

@ -1382,7 +1382,7 @@ static ret_t window_manager_default_on_destroy(widget_t* widget) {
}
#endif /*WITHOUT_WINDOW_ANIMATORS*/
tk_object_unref(TK_OBJECT(wm->native_window));
TK_OBJECT_UNREF(wm->native_window);
return RET_OK;
}

View File

@ -37,10 +37,20 @@ TEST(ScrollBar, basic) {
ASSERT_EQ(value_bool(&v1), value_bool(&v2));
w1 = widget_clone(w, NULL);
ASSERT_EQ(widget_equal(w, w1), TRUE);
str_t str1;
str_t str2;
str_init(&str1, 100);
str_init(&str2, 100);
widget_to_xml(w, &str1);
widget_to_xml(w1, &str2);
ASSERT_STREQ(str1.str, str2.str);
str_reset(&str1);
str_reset(&str2);
widget_destroy(w);
widget_destroy(w1);
idle_manager_dispatch(idle_manager());
}
TEST(ScrollBar, to_xml) {

View File

@ -162,7 +162,7 @@ TEST(Widget_Vtable, all_base_class) {
ASSERT_EQ("all_base_class_on_event_before_children", s_log);
s_log = "";
widget_vtable_on_destroy(all_base_class);
widget_unref(all_base_class);
ASSERT_EQ("all_base_class_on_destroy", s_log);
log_set_hook(NULL, NULL);
@ -314,7 +314,7 @@ TEST(Widget_Vtable, empty_class) {
ASSERT_EQ("all_base_class_on_event_before_children", s_log);
s_log = "";
widget_vtable_on_destroy(widget);
widget_unref(widget);
ASSERT_EQ("all_base_class_on_destroy", s_log);
log_set_hook(NULL, NULL);
@ -473,7 +473,7 @@ TEST(Widget_Vtable, base_class) {
ASSERT_EQ("base_class_on_event_before_children_all_base_class_on_event_before_children", s_log);
s_log = "";
widget_vtable_on_destroy(widget);
widget_unref(widget);
ASSERT_EQ("all_base_class_on_destroy", s_log);
log_set_hook(NULL, NULL);
@ -633,7 +633,7 @@ TEST(Widget_Vtable, sun_class) {
ASSERT_EQ("base_class_on_event_before_children_all_base_class_on_event_before_children", s_log);
s_log = "";
widget_vtable_on_destroy(widget);
widget_unref(widget);
ASSERT_EQ("sun_class_on_destroy_all_base_class_on_destroy", s_log);
log_set_hook(NULL, NULL);