plug mem leaks in stock pixmap code, and refactor code a tiny little bit
authorAlfons Hoogervorst <alfons@proteus.demon.nl>
Tue, 12 Feb 2002 20:58:47 +0000 (20:58 +0000)
committerAlfons Hoogervorst <alfons@proteus.demon.nl>
Tue, 12 Feb 2002 20:58:47 +0000 (20:58 +0000)
ChangeLog.claws
configure.in
src/prefs_common.c
src/stock_pixmap.c
src/stock_pixmap.h

index ba8e6a126de16083e82fcd7cdd2488c750e4568c..9f9bddc853ba0ffeb996312c0bfd5840372da5ed 100644 (file)
@@ -1,3 +1,9 @@
+2002-02-12 [alfons]    0.7.0claws68
+
+       * src/prefs_common.c
+       * src/stock_pixmap.[ch]
+               plug mem leaks, refactor code a little bit
+
 2002-02-12 [sergey]    0.7.0claws67
 
        * src/imap.c
index ae8edd9f9af09956ba8bfa234cc661d009e1942b..0d4296a848c764ac6bc270b946392d84f0f5e083 100644 (file)
@@ -8,7 +8,7 @@ MINOR_VERSION=7
 MICRO_VERSION=0
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws67
+EXTRA_VERSION=claws68
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
index a3de3b00945d286b0e7ac60026994f72296e0d41..1f41d898219be746f63222b5ccc3cc2d41080d67 100644 (file)
@@ -2541,7 +2541,7 @@ static void prefs_interface_create(void)
        gtk_container_add(GTK_CONTAINER(frame_pixmap_theme), vbox_pixmap_theme);
        gtk_container_set_border_width(GTK_CONTAINER(vbox_pixmap_theme), 8);
  
-       stock_pixmap_get_themes(&avail_pixmap_themes);
+       avail_pixmap_themes = stock_pixmap_themes_list_new(); 
  
        combo_pixmap_theme = gtk_combo_new ();
        gtk_widget_show (combo_pixmap_theme);
@@ -2549,6 +2549,8 @@ static void prefs_interface_create(void)
        gtk_combo_set_popdown_strings(GTK_COMBO(combo_pixmap_theme), avail_pixmap_themes);
        entry_pixmap_theme = GTK_COMBO (combo_pixmap_theme)->entry;
 
+       stock_pixmap_themes_list_free(avail_pixmap_themes);
+
        /* interface.checkbtn_emacs          = checkbtn_emacs; */
        interface.checkbtn_openunread         = checkbtn_openunread;
        interface.checkbtn_openinbox          = checkbtn_openinbox;
index 2d5b22e93af57487e665786dab71685db92dd029..3931a8da51cd96331e715952c51555aa9eea87b2 100644 (file)
@@ -17,6 +17,7 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
+#include "defs.h"
 #include <glib.h>
 #include <gtk/gtkwidget.h>
 #include <gtk/gtkpixmap.h>
@@ -25,8 +26,8 @@
 
 #include "stock_pixmap.h"
 #include "gtkutils.h"
+#include "utils.h"
 #include "prefs_common.h"
-#include "defs.h"
 
 #include "pixmaps/address.xpm"
 #include "pixmaps/book.xpm"
@@ -201,16 +202,17 @@ gint stock_pixmap_gdk(GtkWidget *window, StockPixmap icon,
        
                if (strcmp(prefs_common.pixmap_theme_path, DEFAULT_PIXMAP_THEME) != 0) {
                        if ( is_dir_exist(prefs_common.pixmap_theme_path) ) {
-                               char *icon_file_name = g_strconcat(prefs_common.pixmap_theme_path,
-                                                                                        G_DIR_SEPARATOR_S,
-                                                                                        pix_d->file,
-                                                                                        ".xpm",
-                                                                                        NULL);
+                               char *icon_file_name; 
                                
+                               icon_file_name = g_strconcat(prefs_common.pixmap_theme_path,
+                                                            G_DIR_SEPARATOR_S,
+                                                            pix_d->file,
+                                                            ".xpm",
+                                                            NULL);
                                if (file_exist(icon_file_name, FALSE))
                                        PIXMAP_CREATE_FROM_FILE(window, pix, pix_d->mask, icon_file_name);
-
-                               if (pix) pix_d->icon_path = prefs_common.pixmap_theme_path;
+                               if (pix) 
+                                       pix_d->icon_path = prefs_common.pixmap_theme_path;
                                g_free(icon_file_name);
                        } else {
                                /* even the path does not exist (deleted between two sessions), so
@@ -223,13 +225,16 @@ gint stock_pixmap_gdk(GtkWidget *window, StockPixmap icon,
 
        if (!pix_d->pixmap) {
                PIXMAP_CREATE(window, pix_d->pixmap, pix_d->mask, pix_d->data);
-               if (pix_d->pixmap) pix_d->icon_path = DEFAULT_PIXMAP_THEME;     
+               if (pix_d->pixmap) 
+                       pix_d->icon_path = DEFAULT_PIXMAP_THEME;        
        }
 
        g_return_val_if_fail(pix_d->pixmap != NULL, -1);
        
-       if (pixmap) *pixmap = pix_d->pixmap;
-       if (mask)   *mask   = pix_d->mask;
+       if (pixmap) 
+               *pixmap = pix_d->pixmap;
+       if (mask)   
+               *mask   = pix_d->mask;
 
        return 0;
 }
@@ -239,41 +244,67 @@ static void stock_pixmap_find_themes_in_dir(GList **list, const gchar *dirname)
        struct dirent **namelist;
        int n;
 
-       n = scandir(dirname, &namelist, 0, alphasort);
-       if (n > 0) {
-               while(n--) {
-                       gchar *entry = namelist[n]->d_name;
-                       gchar *fullentry = g_strconcat(dirname, G_DIR_SEPARATOR_S, entry, NULL);
-                       if ((strcmp(entry, ".") != 0) && (strcmp(entry, "..") != 0) && (is_dir_exist(fullentry))) {
-                               gchar *filetoexist;
-                               int i;
-                               for ( i = 0; i < N_STOCK_PIXMAPS; i++) {
-                                       filetoexist = g_strconcat(fullentry, G_DIR_SEPARATOR_S, pixmaps[i].file, ".xpm", NULL);
-                                       if (file_exist(filetoexist, FALSE)) {
-                                               *list = g_list_append(*list, fullentry);
-                                               break;
-                                       }
-                                       g_free(filetoexist);
+       if ((n = scandir(dirname, &namelist, 0, alphasort)) <= 0)
+               return;
+
+       while (n--) {
+               gchar *entry;
+               gchar *fullentry;
+
+               entry     = namelist[n]->d_name;
+               fullentry = g_strconcat(dirname, G_DIR_SEPARATOR_S, entry, NULL);
+               
+               if (strcmp(entry, ".") != 0 && strcmp(entry, "..") != 0 && is_dir_exist(fullentry)) {
+                       gchar *filetoexist;
+                       int i;
+                       
+                       for (i = 0; i < N_STOCK_PIXMAPS; i++) {
+                               filetoexist = g_strconcat(fullentry, G_DIR_SEPARATOR_S, pixmaps[i].file, ".xpm", NULL);
+                               if (file_exist(filetoexist, FALSE)) {
+                                       *list = g_list_append(*list, fullentry);
+                                       break;
                                }
+                               g_free(filetoexist);
                        }
-                       g_free(namelist[n]);
+                       if (i == N_STOCK_PIXMAPS) 
+                               g_free(fullentry);
                }
-               g_free(namelist);
+               g_free(namelist[n]);
        }
+       g_free(namelist);
 }
 
-void stock_pixmap_get_themes(GList **list)
+GList *stock_pixmap_themes_list_new(void)
 {
-       gchar *defaulttheme = DEFAULT_PIXMAP_THEME;
-       gchar *userthemes = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
-                                    RC_DIR, G_DIR_SEPARATOR_S, PIXMAP_THEME_DIR, NULL);
-       gchar *systemthemes = g_strconcat(PACKAGE_DATA_DIR, G_DIR_SEPARATOR_S,
-                                        PIXMAP_THEME_DIR, NULL);
+       gchar *defaulttheme;
+       gchar *userthemes;
+       gchar *systemthemes;
+       GList *list = NULL;
        
-       *list = g_list_append(*list, defaulttheme);
+       defaulttheme = g_strdup(DEFAULT_PIXMAP_THEME);
+       userthemes   = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
+                                  RC_DIR, G_DIR_SEPARATOR_S, 
+                                  PIXMAP_THEME_DIR, NULL);
+       systemthemes = g_strconcat(PACKAGE_DATA_DIR, G_DIR_SEPARATOR_S,
+                                  PIXMAP_THEME_DIR, NULL);
+
+       list = g_list_append(list, defaulttheme);
        
-       stock_pixmap_find_themes_in_dir(list, userthemes);
-       stock_pixmap_find_themes_in_dir(list, systemthemes);
+       stock_pixmap_find_themes_in_dir(&list, userthemes);
+       stock_pixmap_find_themes_in_dir(&list, systemthemes);
        
        g_free(userthemes);
+       g_free(systemthemes);
+       return list;
 }
+
+void stock_pixmap_themes_list_free(GList *list)
+{
+       GList *ptr;
+
+       for (ptr = g_list_first(list); ptr != NULL; ptr = g_list_next(ptr)) 
+               if (ptr->data)
+                       g_free(ptr->data);
+       g_list_free(list);              
+}
+
index 8bebfde73daa8d01555a49a04decba3c86004078..3faf61307622b41b9c1e99ae293af612615cdfe2 100644 (file)
@@ -104,5 +104,7 @@ gint stock_pixmap_gdk               (GtkWidget       *window,
                                 GdkPixmap      **pixmap,
                                 GdkBitmap      **mask);
 
-void stock_pixmap_get_themes(GList **list);
+GList *stock_pixmap_themes_list_new    (void);
+void stock_pixmap_themes_list_free     (GList *list);
+
 #endif /* __STOCK_PIXMAP_H__ */