Skip to content

Commit

Permalink
fix valgrind found bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
xianjimli committed Jan 19, 2019
1 parent d191c07 commit 0e829fb
Show file tree
Hide file tree
Showing 7 changed files with 309 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/base/assets_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,9 @@ ret_t assets_manager_unref(assets_manager_t* rm, const asset_info_t* info) {
if (remove) {
tk_compare_t cmp = rm->assets.compare;
rm->assets.compare = pointer_compare;
darray_remove(&(rm->assets), (void*)info);
if(darray_remove(&(rm->assets), (void*)info) == RET_NOT_FOUND) {
asset_info_unref((asset_info_t*)info);
}
rm->assets.compare = cmp;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/base/glyph_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static glyph_cache_item_t* glyph_cache_get_empty(glyph_cache_t* cache) {

item = cache->items + oldest;
if (cache->destroy_glyph) {
cache->destroy_glyph(&(item->g));
cache->destroy_glyph(item->g);
memset(item, 0x00, sizeof(glyph_cache_item_t));
}

Expand Down
2 changes: 1 addition & 1 deletion tests/glyph_cache_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ TEST(GlyphCache, basic) {
uint16_t nr = 10000;
glyph_cache_t cache;
glyph_t g;
glyph_cache_t* c = glyph_cache_init(&cache, 64, NULL);
glyph_cache_t* c = glyph_cache_init(&cache, 64, (tk_destroy_t)glyph_destroy);

for (i = 0; i < nr; i++) {
ASSERT_EQ(glyph_cache_lookup(c, i, size, &g) == RET_NOT_FOUND, true);
Expand Down
9 changes: 0 additions & 9 deletions tests/wstr_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ TEST(WStr, push) {

TEST(WStr, push_int) {
wstr_t str;
wstr_t str1;
int32_t v = 0;
wstr_t* s = &str;
ASSERT_EQ(wstr_init(&str, 0), &str);
Expand All @@ -307,14 +306,6 @@ TEST(WStr, push_int) {
ASSERT_EQ(v, 12345);
s->size = 0;
wstr_reset(&str);

wstr_init(&str1, 0);
wstr_set(&str1, L"0123");
ASSERT_EQ(wstr_push_int(s, "%04d", 123), RET_OK);
ASSERT_EQ(s->size, 4);
ASSERT_EQ(wstr_equal(s, &str1), TRUE);

wstr_reset(&str);
}

TEST(WStr, append) {
Expand Down
9 changes: 9 additions & 0 deletions valgrind/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# valgrind

This works only linux, run it in parent dir:

```
./valgrind/runTest_valgrind.sh
```


294 changes: 294 additions & 0 deletions valgrind/runTest.sup
Original file line number Diff line number Diff line change
@@ -0,0 +1,294 @@
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: possible
fun:calloc
fun:g_malloc0
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
fun:g_type_register_fundamental
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
fun:call_init
fun:_dl_init
obj:/lib/x86_64-linux-gnu/ld-2.27.so
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: possible
fun:malloc
fun:realloc
fun:g_realloc
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
fun:g_type_register_fundamental
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
fun:call_init
fun:_dl_init
obj:/lib/x86_64-linux-gnu/ld-2.27.so
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: possible
fun:calloc
fun:g_malloc0
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
fun:g_type_register_fundamental
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
fun:call_init
fun:_dl_init
obj:/lib/x86_64-linux-gnu/ld-2.27.so
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: possible
fun:malloc
fun:realloc
fun:g_realloc
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
fun:g_type_register_fundamental
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
fun:call_init
fun:_dl_init
obj:/lib/x86_64-linux-gnu/ld-2.27.so
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: possible
fun:calloc
fun:g_malloc0
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
fun:g_type_register_fundamental
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
fun:call_init
fun:_dl_init
obj:/lib/x86_64-linux-gnu/ld-2.27.so
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: possible
fun:malloc
fun:realloc
fun:g_realloc
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
fun:g_type_register_fundamental
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
fun:call_init
fun:_dl_init
obj:/lib/x86_64-linux-gnu/ld-2.27.so
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: possible
fun:calloc
fun:g_malloc0
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
fun:g_type_register_fundamental
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
fun:call_init
fun:_dl_init
obj:/lib/x86_64-linux-gnu/ld-2.27.so
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: possible
fun:malloc
fun:realloc
fun:g_realloc
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
fun:g_type_register_fundamental
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
fun:call_init
fun:_dl_init
obj:/lib/x86_64-linux-gnu/ld-2.27.so
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: possible
fun:calloc
fun:g_malloc0
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
fun:call_init
fun:_dl_init
obj:/lib/x86_64-linux-gnu/ld-2.27.so
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: possible
fun:calloc
fun:g_malloc0
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
fun:g_type_register_fundamental
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
fun:call_init
fun:_dl_init
obj:/lib/x86_64-linux-gnu/ld-2.27.so
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: possible
fun:calloc
fun:g_malloc0
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
fun:g_type_register_fundamental
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
fun:call_init
fun:_dl_init
obj:/lib/x86_64-linux-gnu/ld-2.27.so
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: possible
fun:calloc
fun:g_malloc0
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
fun:g_type_register_fundamental
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
fun:call_init
fun:_dl_init
obj:/lib/x86_64-linux-gnu/ld-2.27.so
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: possible
fun:calloc
fun:g_malloc0
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
fun:g_type_register_fundamental
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
fun:call_init
fun:_dl_init
obj:/lib/x86_64-linux-gnu/ld-2.27.so
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: possible
fun:calloc
fun:g_malloc0
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
fun:g_type_register_fundamental
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
fun:call_init
fun:_dl_init
obj:/lib/x86_64-linux-gnu/ld-2.27.so
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: possible
fun:calloc
fun:g_malloc0
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
fun:g_type_register_fundamental
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
fun:call_init
fun:_dl_init
obj:/lib/x86_64-linux-gnu/ld-2.27.so
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: possible
fun:calloc
fun:g_malloc0
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
fun:g_type_register_fundamental
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
fun:call_init
fun:_dl_init
obj:/lib/x86_64-linux-gnu/ld-2.27.so
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: possible
fun:calloc
fun:g_malloc0
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
fun:g_type_register_fundamental
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
fun:call_init
fun:_dl_init
obj:/lib/x86_64-linux-gnu/ld-2.27.so
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: possible
fun:realloc
fun:g_realloc
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
fun:g_type_register_static
fun:g_param_type_register_static
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
obj:/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.3
fun:call_init
fun:_dl_init
obj:/lib/x86_64-linux-gnu/ld-2.27.so
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: possible
fun:malloc
fun:tk_alloc_impl
fun:tk_alloc
fun:_ZN10ime_pinyin5NGram10load_ngramEP11_rom_file_t
fun:_ZN10ime_pinyin8DictTrie9load_dictEPKcjj
fun:_ZN10ime_pinyin12MatrixSearch4initEPKcS2_
fun:im_open_decoder_rom
fun:input_engine_create
fun:input_method_default_create
fun:input_method_create
fun:tk_init_internal
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: possible
fun:malloc
fun:tk_alloc_impl
fun:tk_alloc
fun:_ZN10ime_pinyin5NGram10load_ngramEP11_rom_file_t
fun:_ZN10ime_pinyin8DictTrie9load_dictEPKcjj
fun:_ZN10ime_pinyin12MatrixSearch4initEPKcS2_
fun:im_open_decoder_rom
fun:input_engine_create
fun:input_method_default_create
fun:input_method_create
fun:tk_init_internal
fun:main
}
1 change: 1 addition & 0 deletions valgrind/runTest_valgrind.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
valgrind --suppressions=valgrind/runTest.sup --leak-check=full ./bin/runTest

0 comments on commit 0e829fb

Please sign in to comment.