Fix a lot of memory leaks.
authorHong Jen Yee (PCMan) <pcman.tw@gmail.com>
Sat, 7 Oct 2006 19:46:37 +0000 (19:46 +0000)
committerHong Jen Yee (PCMan) <pcman.tw@gmail.com>
Sat, 7 Oct 2006 19:46:37 +0000 (19:46 +0000)
src/gtk-run.c
src/misc.c
src/panel.c
src/plugins/icons.c
src/plugins/launchbar.c
src/plugins/ptk-app-menu.c
src/plugins/taskbar.c

index 2d9b680..c611db7 100644 (file)
@@ -57,6 +57,7 @@ static gboolean setup_auto_complete( gpointer entry )
             }
             g_free( filename );
         }
+        g_dir_close( dir );
     }
     g_strfreev( dirnames );
 
@@ -70,8 +71,10 @@ static gboolean setup_auto_complete( gpointer entry )
     g_list_free( list );
 
     gtk_entry_completion_set_model( comp, (GtkTreeModel*)store );
+    g_object_unref( store );
     gtk_entry_completion_set_text_column( comp, 0 );
     gtk_entry_set_completion( (GtkEntry*)entry, comp );
+    g_object_unref( G_OBJECT(comp) );
     return FALSE;
 }
 
@@ -106,7 +109,6 @@ static void on_response( GtkDialog* dlg, gint response, gpointer user_data )
 void gtk_run()
 {
     GtkWidget *win, *entry, *hbox;
-
     win = gtk_dialog_new_with_buttons( _("Run"),
                                        NULL,
                                        GTK_DIALOG_NO_SEPARATOR,
index 07ba0d0..4f80a61 100644 (file)
@@ -380,7 +380,13 @@ get_xaproperty (Window win, Atom prop, Atom type, int *nitems)
     if (XGetWindowProperty (GDK_DISPLAY(), win, prop, 0, 0x7fffffff, False,
               type, &type_ret, &format_ret, &items_ret,
               &after_ret, &prop_data) != Success)
+    {
+        if( G_UNLIKELY(prop_data) )
+            XFree( prop_data );
+        if( nitems )
+            *nitems = 0;
         RET(NULL);
+    }
     if (nitems)
         *nitems = items_ret;
     RET(prop_data);
index e0db68d..3fe53e1 100644 (file)
@@ -206,6 +206,7 @@ panel_event_filter(GdkXEvent *xevent, GdkEvent *event, panel *p)
             }
        } else if (at == a_NET_WORKAREA) {
             DBG("A_NET_WORKAREA\n");
+            g_free( p->workarea );
             p->workarea = get_xaproperty (GDK_ROOT_WINDOW(), a_NET_WORKAREA, XA_CARDINAL, &p->wa_len);
             print_wmdata(p);
         } else
@@ -623,6 +624,8 @@ panel_parse_plugin(panel *p, FILE *fp)
     }
     DBG("plug %s\n", type);
     p->plugins = g_list_append(p->plugins, plug);
+
+    g_free( type );
     RET(1);
     
  error:
@@ -862,6 +865,7 @@ main(int argc, char *argv[], char *env[])
             exit(1);
         }
         fclose(pfp);
+        g_free( cfgfile ); /* FIXME: is it safe to free the string here? */
         if (config)
             configure();
         gtk_main();
index 6eaae68..cc7fd6d 100644 (file)
@@ -71,14 +71,20 @@ get_wmclass(task *tk)
         XFree(tk->ch.res_name);
     if (tk->ch.res_class)
         XFree(tk->ch.res_class);
-    if (!XGetClassHint (gdk_display, tk->win, &tk->ch)) 
+    tk->ch.res_class = tk->ch.res_name = NULL;
+    if (!XGetClassHint (gdk_display, tk->win, &tk->ch))
+    {
+        if( G_UNLIKELY(tk->ch.res_class))
+            XFree(tk->ch.res_class);
+        if( G_UNLIKELY(tk->ch.res_name))
+            XFree(tk->ch.res_name);
         tk->ch.res_class = tk->ch.res_name = NULL;
+    }
     RET();
 }
 
 
 
-
 static inline task *
 find_task (icons * ics, Window win)
 {
@@ -94,6 +100,10 @@ del_task (icons * ics, task *tk, int hdel)
     ics->num_tasks--; 
     if (hdel)
         g_hash_table_remove(ics->task_list, &tk->win);
+    if (tk->ch.res_name)
+        XFree(tk->ch.res_name);
+    if (tk->ch.res_class)
+        XFree(tk->ch.res_class);
     g_free(tk);
     RET();
 }
@@ -221,7 +231,7 @@ static gboolean
 remove_stale_tasks(Window *win, task *tk, gpointer data)
 {
     ENTER;
-    if (tk->refcount-- == 0) {
+    if ( tk->refcount-- == 0) {
         del_task(tk->ics, tk, 0);
         RET(TRUE);
     }
@@ -249,13 +259,14 @@ do_net_client_list(GtkWidget *widget, icons *ics)
 {
     int i;
     task *tk;
-    
+
     ENTER;
     if (ics->wins)
         XFree(ics->wins);
+
     ics->wins = get_xaproperty (GDK_ROOT_WINDOW(), a_NET_CLIENT_LIST, XA_WINDOW, &ics->win_num);
-    if (!ics->wins) 
-       RET();
+    if (!ics->wins)
+        RET();
 
     for (i = 0; i < ics->win_num; i++) {
         if ((tk = g_hash_table_lookup(ics->task_list, &ics->wins[i]))) {
@@ -266,7 +277,7 @@ do_net_client_list(GtkWidget *widget, icons *ics)
             ics->num_tasks++;
             tk->win = ics->wins[i];
             tk->ics = ics;
-            
+
             if (!FBPANEL_WIN(tk->win))
                 XSelectInput (GDK_DISPLAY(), tk->win, PropertyChangeMask | StructureNotifyMask); 
             get_wmclass(tk);
@@ -274,7 +285,7 @@ do_net_client_list(GtkWidget *widget, icons *ics)
             g_hash_table_insert(ics->task_list, &tk->win, tk);
         }
     }
-    
+
     /* remove windows that arn't in the NET_CLIENT_LIST anymore */
     g_hash_table_foreach_remove(ics->task_list, (GHRFunc) remove_stale_tasks, NULL);
     RET();
index 30c2f21..44361bc 100644 (file)
@@ -199,6 +199,7 @@ read_button(plugin *p)
         gchar *full_id = NULL;
         GKeyFile* desktop = g_key_file_new();
         full_id = g_strconcat( "applications/", desktop_id, NULL );
+        g_free( desktop_id );
         if( g_key_file_load_from_data_dirs( desktop, full_id, &desktop_file,
                                             G_KEY_FILE_NONE, NULL ) )
         {
index 3ca413b..0ab498e 100644 (file)
@@ -351,21 +351,27 @@ static void do_load_dir( int prefix_len,
         if( g_file_test(fpath, G_FILE_TEST_IS_DIR) )
         {
             do_load_dir( prefix_len, fpath, sub_menus );
+            g_free( fpath );
             continue;
         }
         if( ! g_str_has_suffix( name, ".desktop" ) )
+        {
+            g_free( fpath );
             continue;
+        }
         file = g_key_file_new();
         g_key_file_load_from_file( file, fpath, 0, NULL );
         if( g_key_file_get_boolean( file, desktop_ent, "NoDisplay", NULL ) )
         {
             g_key_file_free( file );
+            g_free( fpath );
             continue;
         }
         only_show_in = g_key_file_get_string_list( file, desktop_ent, "OnlyShowIn", NULL, NULL );
         if( only_show_in )
         {
             g_key_file_free( file );
+            g_free( fpath );
             g_strfreev( only_show_in );
             continue;
         }
index 4ca5ec0..03db771 100644 (file)
@@ -224,7 +224,7 @@ del_task (taskbar * tb, task *tk, int hdel)
     if( tk->flash_timeout )
         g_source_remove( tk->flash_timeout );
     gtk_widget_destroy(tk->button);
-    tb->num_tasks--; 
+    --tb->num_tasks;
     tk_free_names(tk);     
     if (tb->focused == tk)
         tb->focused = NULL;
@@ -907,16 +907,16 @@ tb_net_client_list(GtkWidget *widget, taskbar *tb)
 {
     int i;
     task *tk;
-    
+
     ENTER;
     if (tb->wins)
         XFree(tb->wins);
     tb->wins = get_xaproperty (GDK_ROOT_WINDOW(), a_NET_CLIENT_LIST, XA_WINDOW, &tb->win_num);
-    if (!tb->wins) 
-       RET();
+    if (!tb->wins)
+        RET();
     for (i = 0; i < tb->win_num; i++) {
         if ((tk = g_hash_table_lookup(tb->task_list, &tb->wins[i]))) {
-            tk->refcount++;
+            ++tk->refcount;
         } else {
             net_wm_window_type nwwt;
             net_wm_state nws;
@@ -927,10 +927,10 @@ tb_net_client_list(GtkWidget *widget, taskbar *tb)
             get_net_wm_window_type(tb->wins[i], &nwwt);
             if (!accept_net_wm_window_type(&nwwt))
                 continue;
-            
+
             tk = g_new0(task, 1);
             tk->refcount = 1;
-            tb->num_tasks++;
+            ++tb->num_tasks;
             tk->win = tb->wins[i];
             tk->tb = tb;
             tk->iconified = (get_wm_state(tk->win) == IconicState);
@@ -940,14 +940,14 @@ tb_net_client_list(GtkWidget *widget, taskbar *tb)
             if( tb->use_urgency_hint && tk_has_urgency(tk)) {
                 tk->urgency = 1;
             }
-         
+
             tk_build_gui(tb, tk);
             tk_set_names(tk);
             g_hash_table_insert(tb->task_list, &tk->win, tk);
             DBG("adding %08x(%p) %s\n", tk->win, FBPANEL_WIN(tk->win), tk->name);
         }
     }
-    
+
     /* remove windows that arn't in the NET_CLIENT_LIST anymore */
     g_hash_table_foreach_remove(tb->task_list, (GHRFunc) tb_remove_stale_tasks, NULL);
     tb_display(tb);