]> git.proxmox.com Git - spiceterm.git/commitdiff
fix memory leaks when using g_hashtable
authorDominik Csapak <d.csapak@proxmox.com>
Fri, 26 May 2017 12:28:12 +0000 (14:28 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 2 Jun 2017 08:54:41 +0000 (10:54 +0200)
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>
input.c
screen.c

diff --git a/input.c b/input.c
index 7fb523894d9e38e73c454678e92aed5769cc9e9a..5ee82de3dc6b9b09308f484bfd7a811d8ec406cd 100644 (file)
--- a/input.c
+++ b/input.c
@@ -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;
     }
index 1fe28a5149b8a58854becc6fc8dbfca3b11b323f..a24fd6ae3b0b2a274ff5cb2b50207ed7e8df95e0 100644 (file)
--- a/screen.c
+++ b/screen.c
@@ -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;