[tracker] libtracker-data: Fixed memory leaks and updated db-config API



commit 3f884d9f5eb1272d1b0d4435344721c77979c887
Author: Martyn Russell <martyn lanedo com>
Date:   Tue Mar 15 12:28:15 2011 +0000

    libtracker-data: Fixed memory leaks and updated db-config API
    
    The db-config API to get the journal rotate destination did return a
    const gchar * but with gsettings a new string is returned each time, so
    the API was updated and memory freed in all places it is called.

 src/libtracker-data/tracker-db-config.c       |   34 +++++++++++-------------
 src/libtracker-data/tracker-db-config.h       |    2 +-
 src/tracker-control/tracker-control-general.c |    3 +-
 3 files changed, 19 insertions(+), 20 deletions(-)
---
diff --git a/src/libtracker-data/tracker-db-config.c b/src/libtracker-data/tracker-db-config.c
index 14cefef..82048a6 100644
--- a/src/libtracker-data/tracker-db-config.c
+++ b/src/libtracker-data/tracker-db-config.c
@@ -15,9 +15,6 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  * 02110-1301  USA
- *
- * Authors:
- * Philip Van Hoof <philip codeminded be>
  */
 
 #include "config.h"
@@ -39,16 +36,16 @@
 #define DEFAULT_JOURNAL_CHUNK_SIZE           50
 #define DEFAULT_JOURNAL_ROTATE_DESTINATION   ""
 
-static void config_set_property         (GObject       *object,
-                                         guint          param_id,
-                                         const GValue  *value,
-                                         GParamSpec    *pspec);
-static void config_get_property         (GObject       *object,
-                                         guint          param_id,
-                                         GValue        *value,
-                                         GParamSpec    *pspec);
-static void config_finalize             (GObject       *object);
-static void config_constructed          (GObject       *object);
+static void config_set_property (GObject      *object,
+                                 guint         param_id,
+                                 const GValue *value,
+                                 GParamSpec   *pspec);
+static void config_get_property (GObject      *object,
+                                 guint         param_id,
+                                 GValue       *value,
+                                 GParamSpec   *pspec);
+static void config_finalize     (GObject      *object);
+static void config_constructed  (GObject      *object);
 
 enum {
 	PROP_0,
@@ -135,7 +132,7 @@ config_get_property (GObject    *object,
 		g_value_set_int (value, tracker_db_config_get_journal_chunk_size (config));
 		break;
 	case PROP_JOURNAL_ROTATE_DESTINATION:
-		g_value_set_string (value, tracker_db_config_get_journal_rotate_destination (config));
+		g_value_take_string (value, tracker_db_config_get_journal_rotate_destination (config));
 		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
@@ -180,12 +177,13 @@ tracker_db_config_new (void)
 gboolean
 tracker_db_config_save (TrackerDBConfig *config)
 {
+	g_return_val_if_fail (TRACKER_IS_DB_CONFIG (config), FALSE);
+
         g_settings_apply (G_SETTINGS (config));
-        //FIXME: make this function return void?
+
         return TRUE;
 }
 
-
 gint
 tracker_db_config_get_journal_chunk_size (TrackerDBConfig *config)
 {
@@ -194,7 +192,7 @@ tracker_db_config_get_journal_chunk_size (TrackerDBConfig *config)
 	return g_settings_get_int (G_SETTINGS (config), "journal-chunk-size");
 }
 
-const gchar *
+gchar *
 tracker_db_config_get_journal_rotate_destination (TrackerDBConfig *config)
 {
 	g_return_val_if_fail (TRACKER_IS_DB_CONFIG (config), DEFAULT_JOURNAL_ROTATE_DESTINATION);
@@ -218,6 +216,6 @@ tracker_db_config_set_journal_rotate_destination (TrackerDBConfig *config,
 {
 	g_return_if_fail (TRACKER_IS_DB_CONFIG (config));
 
-        g_settings_set_string (G_SETTINGS (config), "journal-rotate-destination", g_strdup (value));
+        g_settings_set_string (G_SETTINGS (config), "journal-rotate-destination", value);
 	g_object_notify (G_OBJECT (config), "journal-rotate-destination");
 }
diff --git a/src/libtracker-data/tracker-db-config.h b/src/libtracker-data/tracker-db-config.h
index acae80b..6e4f791 100644
--- a/src/libtracker-data/tracker-db-config.h
+++ b/src/libtracker-data/tracker-db-config.h
@@ -57,7 +57,7 @@ TrackerDBConfig *tracker_db_config_new                            (void);
 gboolean         tracker_db_config_save                           (TrackerDBConfig *config);
 
 gint             tracker_db_config_get_journal_chunk_size         (TrackerDBConfig *config);
-const gchar *    tracker_db_config_get_journal_rotate_destination (TrackerDBConfig *config);
+gchar *          tracker_db_config_get_journal_rotate_destination (TrackerDBConfig *config);
 
 void             tracker_db_config_set_journal_chunk_size         (TrackerDBConfig *config,
                                                                    gint             value);
diff --git a/src/tracker-control/tracker-control-general.c b/src/tracker-control/tracker-control-general.c
index 2ef09c6..fe2b0e2 100644
--- a/src/tracker-control/tracker-control-general.c
+++ b/src/tracker-control/tracker-control-general.c
@@ -395,7 +395,7 @@ tracker_control_general_run (void)
 
 	if (hard_reset || soft_reset) {
 		guint log_handler_id;
-		const gchar *rotate_to = NULL;
+		gchar *rotate_to;
 		TrackerDBConfig *db_config;
 		gsize chunk_size;
 		gint chunk_size_mb;
@@ -418,6 +418,7 @@ tracker_control_general_run (void)
 		tracker_db_journal_set_rotating ((chunk_size_mb != -1),
 		                                 chunk_size, rotate_to);
 
+		g_free (rotate_to);
 		g_object_unref (db_config);
 
 		/* Clean up (select_cache_size and update_cache_size don't matter here) */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]