fix a couple of memory leaks
[claws.git] / src / prefs_gtk.c
index 1debd77ef7f8cbf4a07f6f0c7b5ad82e666fe3d4..dc7e5cf10f6c98d4464fe199e01d8cdcacbf89d5 100644 (file)
@@ -19,6 +19,7 @@
 
 #ifdef HAVE_CONFIG_H
 #  include "config.h"
+#include "claws-features.h"
 #endif
 
 #define _GNU_SOURCE
@@ -40,7 +41,6 @@
 #include "utils.h"
 #include "gtkutils.h"
 #include "passcrypt.h"
-#include "base64.h"
 #include "codeconv.h"
 
 #define CL(x)  (((gulong) (x) >> (gulong) 8) & 0xFFUL)
@@ -219,14 +219,16 @@ static void prefs_config_parse_one_line(PrefParam *param, const gchar *buf)
                case P_PASSWORD:
                        g_free(*((gchar **)param[i].data));
                        if (value[0] == '!') {
-                               gchar tmp[1024];
-                               gint len;
-
-                               len = base64_decode(tmp, &value[1], strlen(value) - 1);
-                               passcrypt_decrypt(tmp, len);
-                               tmp[len] = '\0';
+                               gchar *tmp, buf[1024];
+                               gsize len;
+
+                               tmp = g_base64_decode(&value[1], &len);
+                               g_strlcat(buf, tmp, 1024);
+                               g_free(tmp);
+                               buf[len] = '\0';
+                               passcrypt_decrypt(buf, len);
                                *((gchar **)param[i].data) =
-                                       *tmp ? g_strdup(tmp) : NULL;
+                                       *buf ? g_strdup(buf) : NULL;
                        } else {
                                *((gchar **)param[i].data) =
                                        *value ? g_strdup(value) : NULL;
@@ -382,7 +384,7 @@ gint prefs_write_param(PrefParam *param, FILE *fp)
                        break;
                case P_PASSWORD:
                        {
-                               gchar *tmp = NULL, tmp2[1024] = {0};
+                               gchar *tmp = NULL, *tmp2 = NULL;
 
                                tmp = *((gchar **)param[i].data);
                                if (tmp) {
@@ -391,13 +393,14 @@ gint prefs_write_param(PrefParam *param, FILE *fp)
                                        tmp = g_strdup(tmp);
                                        len = strlen(tmp);
                                        passcrypt_encrypt(tmp, len);
-                                       base64_encode(tmp2, tmp, len);
+                                       tmp2 = g_base64_encode(tmp, len);
                                        g_free(tmp);
                                        tmp = tmp2;
                                }
                                g_snprintf(buf, sizeof(buf), "%s=!%s\n", param[i].name,
                                           tmp ?
                                           tmp : "");
+                               g_free(tmp);
                        }
                        break;
                default:
@@ -451,11 +454,9 @@ void prefs_set_default(PrefParam *param)
                                                g_strconcat(get_home_dir(),
                                                            param[i].defval + 1,
                                                            NULL);
-                               else if (param[i].defval[0] != '\0')
+                               else 
                                        *((gchar **)param[i].data) =
                                                g_strdup(param[i].defval);
-                               else
-                                       *((gchar **)param[i].data) = NULL;
                        } else
                                *((gchar **)param[i].data) = NULL;
                        break;