memory leak found by valgrind

This commit is contained in:
lixianjing 2020-12-01 10:30:44 +08:00
parent 71bb25203a
commit 74724ac9ce
4 changed files with 23 additions and 6 deletions

View File

@ -34,6 +34,13 @@ bitmap_t* bitmap_create(void) {
return bitmap;
}
ret_t bitmap_destroy_with_self(bitmap_t* bitmap) {
return_value_if_fail(bitmap != NULL, RET_BAD_PARAMS);
bitmap->should_free_handle = TRUE;
return bitmap_destroy(bitmap);
}
ret_t bitmap_destroy(bitmap_t* bitmap) {
return_value_if_fail(bitmap != NULL, RET_BAD_PARAMS);

View File

@ -260,10 +260,20 @@ bool_t bitmap_save_png(bitmap_t* bitmap, const char* filename);
*/
ret_t bitmap_mono_dump(const uint8_t* buff, uint32_t w, uint32_t h);
/**
* @method bitmap_destroy_with_self
* (for script only)
* @alias bitmap_destroy
* @annotation ["deconstructor", "scriptable", "gc"]
* @param {bitmap_t*} bitmap bitmap对象
* @return {ret_t} RET_OK表示成功
*/
ret_t bitmap_destroy_with_self(bitmap_t* bitmap);
/**
* @method bitmap_destroy
*
* @annotation ["deconstructor", "scriptable", "gc"]
* @annotation ["deconstructor"]
* @param {bitmap_t*} bitmap bitmap对象
* @return {ret_t} RET_OK表示成功
*/

View File

@ -20,16 +20,16 @@ TEST(ImageManager, basic) {
TEST(ImageManager, allloc) {
bitmap_t* bmp = bitmap_create();
ASSERT_EQ(image_manager_get_bitmap(image_manager(), "checked", bmp), RET_OK);
bitmap_destroy(bmp);
bitmap_destroy_with_self(bmp);
bmp = bitmap_create();
ASSERT_EQ(image_manager_lookup(image_manager(), "checked", bmp), RET_OK);
ASSERT_EQ(image_manager_get_bitmap(image_manager(), "not found", bmp), RET_NOT_FOUND);
bitmap_destroy(bmp);
bitmap_destroy_with_self(bmp);
bmp = bitmap_create();
ASSERT_EQ(image_manager_lookup(image_manager(), "unchecked", bmp), RET_NOT_FOUND);
bitmap_destroy(bmp);
bitmap_destroy_with_self(bmp);
ASSERT_EQ(image_manager_unload_unused(image_manager(), 0), RET_OK);
}

View File

@ -79,7 +79,7 @@ TEST(TabButton, change_value) {
ASSERT_EQ(value_bool(&(evt.old_value)), FALSE);
ASSERT_EQ(value_bool(&(evt.new_value)), TRUE);
widget_destroy(w);
widget_destroy(g);
idle_dispatch();
}
@ -94,6 +94,6 @@ TEST(TabButton, change_value_abort) {
ASSERT_EQ(widget_set_prop_bool(w, WIDGET_PROP_VALUE, TRUE), RET_OK);
ASSERT_EQ(widget_get_prop_bool(w, WIDGET_PROP_VALUE, TRUE), FALSE);
widget_destroy(w);
widget_destroy(g);
idle_dispatch();
}