fix memory leak found by valgrind

This commit is contained in:
lixianjing 2021-09-22 17:44:38 +08:00
parent 3f462ca37b
commit 276e38f25b
4 changed files with 8 additions and 2 deletions

View File

@ -207,6 +207,8 @@ static gradient_t* gradient_parse_str(gradient_t* gradient, const char* str) {
t->cursor++;
gradient_parse_radial(gradient, t);
}
tokenizer_deinit(t);
return gradient;
}

View File

@ -619,7 +619,9 @@ ret_t value_reset(value_t* v) {
TKMEM_FREE(v->value.sized_str.str);
break;
}
case VALUE_TYPE_BINARY: {
case VALUE_TYPE_BINARY:
case VALUE_TYPE_UBJSON:
case VALUE_TYPE_GRADIENT: {
TKMEM_FREE(v->value.binary_data.data);
break;
}

View File

@ -24,6 +24,8 @@ static ret_t on_style_item(void* ctx, const char* widget_state, const char* id,
gradient_to_str(&g, &s);
snprintf(str, sizeof(str), "%s,%s,\"%s\";", widget_state, id, s.str);
gradient_deinit(&g);
str_reset(&s);
} else {
snprintf(str, sizeof(str), "%s,%s,%d;", widget_state, id, value_int(val));
}

View File

@ -58,7 +58,6 @@ TEST(UILoaderXML, attr) {
ASSERT_EQ(builder->root != NULL, true);
widget_layout(builder->root);
ui_builder_destroy(builder);
b1 = widget_lookup(builder->root, "b1", TRUE);
ASSERT_EQ(b1 != NULL, true);
ASSERT_EQ(b1->x, 10);
@ -92,6 +91,7 @@ TEST(UILoaderXML, attr) {
ASSERT_EQ(b4->h, 20);
widget_destroy(builder->root);
ui_builder_destroy(builder);
}
TEST(UILoaderXML, prop1) {