5
0
mirror of git://git.proxmox.com/git/spiceterm.git synced 2025-03-11 16:58:29 +03:00

fix memory leaks when using g_hashtable

when generating a bitmap for a character whose codepoint was above 255,
we used a cache_id of 0, malloc'd a CachedImage and inserted it into a
g_hashtable, without freeing the one which was before inserted with cache_id 0

this is circumvented by only generating a CachedImage when having
a cache_id != 0

the second leak was also with inserting into a hashtable, but there we
give the hashtable the g_free method as a value_destroy_func

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2017-05-26 14:28:12 +02:00 committed by Wolfgang Bumiller
parent 377a4ee926
commit ffeedb040b
2 changed files with 9 additions and 6 deletions

View File

@ -837,8 +837,8 @@ spiceterm_create(uint32_t width, uint32_t height, SpiceTermOptions *opts)
SpiceCoreInterface *core = basic_event_loop_init();
SpiceScreen *spice_screen = spice_screen_new(core, width, height, opts);
keymap = g_hash_table_new(g_int_hash, g_int_equal);
keymap = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, g_free);
if (!parse_keymap(opts->keymap ? opts->keymap : "en-us")) {
return NULL;
}

View File

@ -297,10 +297,13 @@ spice_screen_draw_char_cmd(SpiceScreen *spice_screen, int x, int y, int c,
dst += 4;
}
}
ce = g_new(CachedImage, 1);
ce->cache_id = cache_id;
ce->bitmap = bitmap;
g_hash_table_insert(spice_screen->image_cache, &ce->cache_id, ce);
if (cache_id != 0) {
ce = g_new(CachedImage, 1);
ce->cache_id = cache_id;
ce->bitmap = bitmap;
g_hash_table_insert(spice_screen->image_cache, &ce->cache_id, ce);
}
}
bbox.left = left; bbox.top = top;