[vlc-devel] [PATCH] xcb: fix some memory leaks

Edward Wang edward.c.wang at compdigitec.com
Mon Jun 24 17:13:39 CEST 2013


According to xcb docs, we are responsible for freeing this memory.
---
 modules/control/globalhotkeys/xcb.c |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/modules/control/globalhotkeys/xcb.c b/modules/control/globalhotkeys/xcb.c
index f35ce67..6a2c93f 100644
--- a/modules/control/globalhotkeys/xcb.c
+++ b/modules/control/globalhotkeys/xcb.c
@@ -183,7 +183,7 @@ static unsigned GetModifier( xcb_connection_t *p_connection, xcb_key_symbols_t *
 
     const xcb_keycode_t *p_keys = xcb_key_symbols_get_keycode( p_symbols, sym );
     if( !p_keys )
-        return 0;
+        goto error;
 
     int i = 0;
     bool no_modifier = true;
@@ -198,28 +198,33 @@ static unsigned GetModifier( xcb_connection_t *p_connection, xcb_key_symbols_t *
     }
 
     if( no_modifier )
-        return 0;
+        goto error;
 
     xcb_get_modifier_mapping_cookie_t r =
             xcb_get_modifier_mapping( p_connection );
     xcb_get_modifier_mapping_reply_t *p_map =
             xcb_get_modifier_mapping_reply( p_connection, r, NULL );
     if( !p_map )
-        return 0;
+        goto error;
 
     xcb_keycode_t *p_keycode = xcb_get_modifier_mapping_keycodes( p_map );
     if( !p_keycode )
-        return 0;
+        goto error;
 
     for( int i = 0; i < 8; i++ )
         for( int j = 0; j < p_map->keycodes_per_modifier; j++ )
             for( int k = 0; p_keys[k] != XCB_NO_SYMBOL; k++ )
                 if( p_keycode[i*p_map->keycodes_per_modifier + j] == p_keys[k])
                 {
+                    free( p_keys );
+                    free( p_keycode );
                     free( p_map );
                     return pi_mask[i];
                 }
 
+    error:
+    free( p_keys );
+    free( p_keycode );
     free( p_map ); // FIXME to check
     return 0;
 }
-- 
1.7.5.4




More information about the vlc-devel mailing list