fix memory leak

This commit is contained in:
lixianjing 2021-12-27 17:45:48 +08:00
parent 98e7824a6b
commit 56ed573ecb
4 changed files with 30 additions and 14 deletions

View File

@ -5,6 +5,8 @@
* 修复demoui kb\_ascii软键盘输入内容错误问题感谢兆坤提供补丁
* 将page\_tab\_ctrl中的view改为tab\_control让xml更具有可读性感谢兆坤提供补丁
* 修复mledit选择文本时鼠标指针拖到滚动条上的滑块后再拖回mledit时无法继续选择文本的问题感谢兆坤提供补丁
* 修复SDL\_DestroyWindow后SDL\_GL\_DeleteContext无法正常释放导致泄漏的问题感谢朝泽提供补丁
* 修复data\_reader\_factory、data\_writer\_factory重复register会引起内存泄漏的问题感谢朝泽提供补丁
2021/12/26
* 增加函数array\_reverse

View File

@ -189,14 +189,14 @@ static ret_t native_window_sdl_close(native_window_t* win) {
SDL_DestroyRenderer(sdl->render);
}
if (sdl->window != NULL) {
SDL_DestroyWindow(sdl->window);
}
if (sdl->context != NULL) {
SDL_GL_DeleteContext(sdl->context);
}
if (sdl->window != NULL) {
SDL_DestroyWindow(sdl->window);
}
sdl->render = NULL;
sdl->window = NULL;
sdl->context = NULL;

View File

@ -61,12 +61,19 @@ ret_t data_reader_factory_register(data_reader_factory_t* factory, const char* p
creator_item_t* item = NULL;
return_value_if_fail(factory != NULL && protocol != NULL && create != NULL, RET_BAD_PARAMS);
item = TKMEM_ZALLOC(creator_item_t);
return_value_if_fail(item != NULL, RET_OOM);
item = darray_find(&(factory->creators), (void*)protocol);
if (item != NULL) {
if (item->create != create) {
item->create = create;
}
} else {
item = TKMEM_ZALLOC(creator_item_t);
return_value_if_fail(item != NULL, RET_OOM);
item->create = create;
tk_strncpy(item->protocol, protocol, TK_NAME_LEN);
darray_push(&(factory->creators), item);
item->create = create;
tk_strncpy(item->protocol, protocol, TK_NAME_LEN);
darray_push(&(factory->creators), item);
}
return RET_OK;
}

View File

@ -61,12 +61,19 @@ ret_t data_writer_factory_register(data_writer_factory_t* factory, const char* p
creator_item_t* item = NULL;
return_value_if_fail(factory != NULL && protocol != NULL && create != NULL, RET_BAD_PARAMS);
item = TKMEM_ZALLOC(creator_item_t);
return_value_if_fail(item != NULL, RET_OOM);
item = darray_find(&(factory->creators), (void*)protocol);
if (item != NULL) {
if (item->create != create) {
item->create = create;
}
} else {
item = TKMEM_ZALLOC(creator_item_t);
return_value_if_fail(item != NULL, RET_OOM);
item->create = create;
tk_strncpy(item->protocol, protocol, TK_NAME_LEN);
darray_push(&(factory->creators), item);
item->create = create;
tk_strncpy(item->protocol, protocol, TK_NAME_LEN);
darray_push(&(factory->creators), item);
}
return RET_OK;
}