[Commits] [SCM] claws branch, master, updated. 3.11.1-161-gcb87edf

mones at claws-mail.org mones at claws-mail.org
Tue Jun 23 10:08:24 CEST 2015


The branch, master has been updated
       via  cb87edf1710e8021ed0affc2157cf0c340660c72 (commit)
      from  601733aa309a83af7871a7d209386a978c086106 (commit)

Summary of changes:
 src/plugins/libravatar/Makefile.am                 |    1 +
 src/plugins/libravatar/libravatar.c                |   26 ++--------
 src/plugins/libravatar/libravatar.h                |    1 -
 src/plugins/libravatar/libravatar_cache.c          |   52 ++++++++++++++++++++
 ...{libravatar_federation.h => libravatar_cache.h} |   14 ++++--
 5 files changed, 65 insertions(+), 29 deletions(-)
 create mode 100644 src/plugins/libravatar/libravatar_cache.c
 copy src/plugins/libravatar/{libravatar_federation.h => libravatar_cache.h} (72%)


- Log -----------------------------------------------------------------
commit cb87edf1710e8021ed0affc2157cf0c340660c72
Author: Ricardo Mones <ricardo at mones.org>
Date:   Tue Jun 23 00:38:31 2015 +0200

    Libravatar: refactor and fix leak on corner case
    
     • Move cache initialization to its own file
     • Fix leaked cache_dir path when initialization failed

diff --git a/src/plugins/libravatar/Makefile.am b/src/plugins/libravatar/Makefile.am
index df30379..7edf1f5 100644
--- a/src/plugins/libravatar/Makefile.am
+++ b/src/plugins/libravatar/Makefile.am
@@ -78,6 +78,7 @@ libravatar_la_CPPFLAGS = \
 libravatar_la_SOURCES = \
 	libravatar.c libravatar.h \
 	libravatar_prefs.c libravatar_prefs.h \
+	libravatar_cache.c libravatar_cache.h \
 	libravatar_missing.c libravatar_missing.h \
 	libravatar_federation.c libravatar_federation.h
 
diff --git a/src/plugins/libravatar/libravatar.c b/src/plugins/libravatar/libravatar.c
index a09e6d0..b597aa5 100644
--- a/src/plugins/libravatar/libravatar.c
+++ b/src/plugins/libravatar/libravatar.c
@@ -30,6 +30,7 @@
 #include "version.h"
 #include "libravatar.h"
 #include "libravatar_prefs.h"
+#include "libravatar_cache.h"
 #include "libravatar_missing.h"
 #include "libravatar_federation.h"
 #include "prefs_common.h"
@@ -312,29 +313,8 @@ static gboolean libravatar_image_render_hook(gpointer source, gpointer data)
 
 static gint cache_dir_init()
 {
-	gchar *subdir;
-	int i;
-
-	cache_dir = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
-				LIBRAVATAR_CACHE_DIR, G_DIR_SEPARATOR_S,
-				NULL);
-	if (!is_dir_exist(cache_dir)) {
-		if (make_dir(cache_dir) < 0) {
-			g_free(cache_dir);
-			return -1;
-		}
-	}
-	for (i = DEF_MODE_MM; i <= DEF_MODE_RETRO; ++i) {
-		subdir = g_strconcat(cache_dir, def_mode[i - 10], NULL);
-		if (!is_dir_exist(subdir)) {
-			if (make_dir(subdir) < 0) {
-				g_warning("cannot create directory %s\n", subdir);
-				g_free(subdir);
-				return -1;
-			}
-		}
-		g_free(subdir);
-	}
+	cache_dir = libravatar_cache_init(def_mode, DEF_MODE_MM - 10, DEF_MODE_RETRO - 10);
+	cm_return_val_if_fail (cache_dir != NULL, -1);
 
 	return 0;
 }
diff --git a/src/plugins/libravatar/libravatar.h b/src/plugins/libravatar/libravatar.h
index 9bb3c2e..70d6bfc 100644
--- a/src/plugins/libravatar/libravatar.h
+++ b/src/plugins/libravatar/libravatar.h
@@ -31,7 +31,6 @@
 
 #define AVATAR_LIBRAVATAR 3
 #define AVATAR_SIZE 48
-#define LIBRAVATAR_CACHE_DIR "avatarcache"
 /* https://github.com/mathiasbynens/small/pull/19 */
 #define MIN_PNG_SIZE 67L
 #define MAX_URL_LENGTH 1024
diff --git a/src/plugins/libravatar/libravatar_cache.c b/src/plugins/libravatar/libravatar_cache.c
new file mode 100644
index 0000000..d4be79d
--- /dev/null
+++ b/src/plugins/libravatar/libravatar_cache.c
@@ -0,0 +1,52 @@
+/*
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2015 Hiroyuki Yamamoto and the Claws Mail Team
+ * Copyright (C) 2014-2015 Ricardo Mones
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "libravatar_cache.h"
+#include "utils.h"
+
+gchar *libravatar_cache_init(const char *dirs[], gint start, gint end)
+{
+	gchar *subdir, *rootdir;
+	int i;
+
+	rootdir = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
+				LIBRAVATAR_CACHE_DIR, G_DIR_SEPARATOR_S,
+				NULL);
+	if (!is_dir_exist(rootdir)) {
+		if (make_dir(rootdir) < 0) {
+			g_warning("cannot create root directory %s\n", subdir);
+			g_free(rootdir);
+			return NULL;
+		}
+	}
+	for (i = start; i <= end; ++i) {
+		subdir = g_strconcat(rootdir, dirs[i], NULL);
+		if (!is_dir_exist(subdir)) {
+			if (make_dir(subdir) < 0) {
+				g_warning("cannot create directory %s\n", subdir);
+				g_free(subdir);
+				g_free(rootdir);
+				return NULL;
+			}
+		}
+		g_free(subdir);
+	}
+
+	return rootdir;
+}
diff --git a/src/plugins/libravatar/libravatar.h b/src/plugins/libravatar/libravatar_cache.h
similarity index 52%
copy from src/plugins/libravatar/libravatar.h
copy to src/plugins/libravatar/libravatar_cache.h
index 9bb3c2e..a0150f3 100644
--- a/src/plugins/libravatar/libravatar.h
+++ b/src/plugins/libravatar/libravatar_cache.h
@@ -1,7 +1,7 @@
 /*
  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2014 Hiroyuki Yamamoto and the Claws Mail Team
- * Copyright (C) 2014 Ricardo Mones
+ * Copyright (C) 1999-2015 Hiroyuki Yamamoto and the Claws Mail Team
+ * Copyright (C) 2014-2015 Ricardo Mones
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -17,33 +17,15 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef __LIBRAVATAR_H
-#define __LIBRAVATAR_H
+#ifndef __LIBRAVATAR_CACHE_H
+#define __LIBRAVATAR_CACHE_H
 
 #include <glib.h>
 
-#include "version.h"
-#include "claws.h"
-#include "plugin.h"
-#include "utils.h"
-#include "hooks.h"
-#include "avatars.h"
-
-#define AVATAR_LIBRAVATAR 3
-#define AVATAR_SIZE 48
 #define LIBRAVATAR_CACHE_DIR "avatarcache"
-/* https://github.com/mathiasbynens/small/pull/19 */
-#define MIN_PNG_SIZE 67L
-#define MAX_URL_LENGTH 1024
 
-gint 		plugin_init	  	  (gchar **error);
-gboolean	plugin_done		  (void);
-const gchar *	plugin_name		  (void);
-const gchar *	plugin_desc		  (void);
-const gchar *	plugin_type		  (void);
-const gchar *	plugin_licence		  (void);
-const gchar *	plugin_version		  (void);
-struct PluginFeature *plugin_provides	  (void);
+gchar	*libravatar_cache_init		(const char *dirs[],
+					 gint start,
+					 gint end);
 
 #endif
-

-----------------------------------------------------------------------


hooks/post-receive
-- 
Claws Mail


More information about the Commits mailing list