[bijiben] Fix leak on biji_note_obj_get_path



commit 009bc3e9140a6a89373374a1ef3a965165f9766a
Author: Pierre-Yves Luyten <py luyten fr>
Date:   Fri Feb 8 21:40:17 2013 +0100

    Fix leak on biji_note_obj_get_path
    
    The returned string must be freed

 src/bjb-bijiben.c                                 |    5 ++++-
 src/bjb-controller.c                              |    9 +++++++--
 src/libbiji/biji-note-book.c                      |   15 +++++++++------
 src/libbiji/biji-tracker.c                        |   20 +++++++++++++++-----
 src/libbiji/biji-zeitgeist.c                      |    6 ++++--
 src/libbiji/deserializer/biji-lazy-deserializer.c |    9 +++++++--
 6 files changed, 46 insertions(+), 18 deletions(-)
---
diff --git a/src/bjb-bijiben.c b/src/bjb-bijiben.c
index 6ca53bd..e565927 100644
--- a/src/bjb-bijiben.c
+++ b/src/bjb-bijiben.c
@@ -181,9 +181,10 @@ go_through_notes_cb (GFileEnumerator *enumerator, GAsyncResult *res, Bijiben *se
   for (l = notes_proposal; l != NULL; l = l->next)
   {
     BijiNoteObj *note = l->data;
+    gchar *path = biji_note_obj_get_path (note);
 
     /* Don't add an already imported note */
-    if (note_book_get_note_at_path (self->priv->book, biji_note_obj_get_path (note)))
+    if (note_book_get_note_at_path (self->priv->book, path))
     {
       abort_note (note);
     }
@@ -208,6 +209,8 @@ go_through_notes_cb (GFileEnumerator *enumerator, GAsyncResult *res, Bijiben *se
       biji_note_book_append_new_note (self->priv->book, note, FALSE);
       biji_note_obj_save_note (note);
     }
+
+    g_free (path);
   }
 
   /* NoteBook will notify for all opened windows */
diff --git a/src/bjb-controller.c b/src/bjb-controller.c
index ced9690..f07ccf2 100644
--- a/src/bjb-controller.c
+++ b/src/bjb-controller.c
@@ -180,6 +180,7 @@ bjb_controller_add_note ( BijiNoteObj *note, BjbController *self )
   GtkTreeIter    iter;
   GtkListStore  *store;
   GdkPixbuf     *pix = NULL;
+  gchar *path;
 
   store = GTK_LIST_STORE(self->priv->model);
 
@@ -203,17 +204,21 @@ bjb_controller_add_note ( BijiNoteObj *note, BjbController *self )
 
     /* Appart from pixbuf, both icon & list view types
      * currently use the same model */
+    path = biji_note_obj_get_path (note);
+
     gtk_list_store_append (store,&iter);
     gtk_list_store_set (store, 
                         &iter,
-                        COL_URN,    biji_note_obj_get_path(note),
-                        COL_URI,    biji_note_obj_get_path(note),
+                        COL_URN,    path,
+                        COL_URI,    path,
                         COL_NAME,   biji_note_obj_get_title(note),
                         COL_AUTHOR,   NULL,
                         COL_IMAGE,  pix,
                         COL_MTIME,  biji_note_obj_get_last_change_date_sec(note),
                         COL_SELECTED, FALSE,
                         -1);
+
+    g_free (path);
   }
 }
 
diff --git a/src/libbiji/biji-note-book.c b/src/libbiji/biji-note-book.c
index bbacdc2..c5fc94c 100644
--- a/src/libbiji/biji-note-book.c
+++ b/src/libbiji/biji-note-book.c
@@ -63,7 +63,7 @@ biji_note_book_init (BijiNoteBook *self)
   /* Note path is key for table. It's freed by note itself */
   self->priv->notes = g_hash_table_new_full (g_str_hash,
                                              g_str_equal,
-                                             NULL,
+                                             g_free,
                                              g_object_unref);
 }
 
@@ -360,21 +360,24 @@ gboolean
 _note_book_remove_one_note(BijiNoteBook *book,BijiNoteObj *note)
 {
   BijiNoteObj *to_delete = NULL;
+  gchar *path;
+  gboolean retval = FALSE;
 
-  to_delete = g_hash_table_lookup (book->priv->notes,
-                                  biji_note_obj_get_path(note));
+  path = biji_note_obj_get_path (note);
+  to_delete = g_hash_table_lookup (book->priv->notes, path);
 
   if (to_delete)
   {
     /* Ref note first, hash_table won't finalize it & we can delete it*/
     g_object_ref (to_delete);
-    g_hash_table_remove (book->priv->notes, biji_note_obj_get_path (note));
+    g_hash_table_remove (book->priv->notes, path);
     biji_note_obj_trash (note);
     g_signal_emit ( G_OBJECT (book), biji_book_signals[BOOK_AMENDED],0);
-    return TRUE;
+    retval = TRUE;
   }
 
-  return FALSE;
+  g_free (path);
+  return retval;
 }
 
 /* Notes collection */
diff --git a/src/libbiji/biji-tracker.c b/src/libbiji/biji-tracker.c
index 4affce7..2684d9c 100644
--- a/src/libbiji/biji-tracker.c
+++ b/src/libbiji/biji-tracker.c
@@ -137,7 +137,12 @@ to_8601_date( gchar * dot_iso_8601_date )
 static gchar *
 get_note_url (BijiNoteObj *note)
 {
-  return g_strdup_printf ("file://%s", biji_note_obj_get_path (note));
+  gchar *path, *retval;
+
+  path = biji_note_obj_get_path (note);
+  retval = g_strdup_printf ("file://%s", path);
+  g_free (path);
+  return retval;
 }
 
 /////////////// Tags
@@ -305,8 +310,11 @@ biji_remove_collection_from_note (BijiNoteObj *note, gchar *urn)
 void
 biji_note_delete_from_tracker (BijiNoteObj *note)
 {
-  gchar *query = g_strdup_printf ("DELETE { <%s> a rdfs:Resource }",
-                                        biji_note_obj_get_path(note));
+  gchar *query, *path;
+
+  path = biji_note_obj_get_path (note);
+  query = g_strdup_printf ("DELETE { <%s> a rdfs:Resource }", path);
+  g_free (path);
 
   biji_perform_update_async_and_free (query, NULL, NULL);
 }
@@ -314,13 +322,14 @@ biji_note_delete_from_tracker (BijiNoteObj *note)
 void
 bijiben_push_note_to_tracker (BijiNoteObj *note)
 {
-  gchar *title,*content,*file,*create_date,*last_change_date ;
+  gchar *title,*content,*file,*create_date,*last_change_date, *path;
     
   title = tracker_str (biji_note_obj_get_title (note));
   file = g_strdup_printf ("file://%s", biji_note_obj_get_path(note));
   create_date = to_8601_date (biji_note_obj_get_last_change_date (note));
   last_change_date = to_8601_date (biji_note_obj_get_last_change_date (note));
   content = tracker_str (biji_note_get_raw_text (note));
+  path = biji_note_obj_get_path (note);
 
   /* TODO : nie:mimeType Note ;
    * All these properties are unique and thus can be "updated"
@@ -333,7 +342,7 @@ bijiben_push_note_to_tracker (BijiNoteObj *note)
                             nie:title '%s' ; \
                             nie:plainTextContent '%s' ; \
                             nie:generator 'Bijiben' . }",
-                           biji_note_obj_get_path(note),
+                           path,
                            file,
                            last_change_date,
                            create_date,
@@ -347,5 +356,6 @@ bijiben_push_note_to_tracker (BijiNoteObj *note)
   g_free(content); 
   g_free(create_date);
   g_free(last_change_date);
+  g_free (path);
 }
 
diff --git a/src/libbiji/biji-zeitgeist.c b/src/libbiji/biji-zeitgeist.c
index 3bf38cf..d7a7d20 100644
--- a/src/libbiji/biji-zeitgeist.c
+++ b/src/libbiji/biji-zeitgeist.c
@@ -33,12 +33,14 @@ get_log (void)
 void 
 insert_zeitgeist(BijiNoteObj *note, const char *action)
 {
-  gchar *uri;
+  gchar *uri, *path;
   ZeitgeistEvent     *event;
   ZeitgeistSubject   *subject ;
   ZeitgeistLog       *log = get_log() ;
 
-  uri = g_strdup_printf ("file://%s", biji_note_obj_get_path (note));
+  path = biji_note_obj_get_path (note);
+  uri = g_strdup_printf ("file://%s", path);
+  g_free (path);
 
   subject = zeitgeist_subject_new_full (uri,                            //URI
                                         ZEITGEIST_NFO_DOCUMENT,         //inter
diff --git a/src/libbiji/deserializer/biji-lazy-deserializer.c b/src/libbiji/deserializer/biji-lazy-deserializer.c
index adcbb50..d381566 100644
--- a/src/libbiji/deserializer/biji-lazy-deserializer.c
+++ b/src/libbiji/deserializer/biji-lazy-deserializer.c
@@ -518,11 +518,14 @@ gboolean
 biji_lazy_deserialize_internal (BijiLazyDeserializer *self)
 {
   BijiNoteObj* n = self->priv->note;
+  gchar *path;
   xmlDocPtr doc;
   xmlNodePtr cur;
   xmlChar     *version; 
 
-  doc = xmlParseFile (biji_note_obj_get_path (n));
+  path = biji_note_obj_get_path (n);
+  doc = xmlParseFile (path);
+  g_free (path);
 
   if (doc == NULL ) 
   {
@@ -578,7 +581,9 @@ biji_lazy_deserialize_internal (BijiLazyDeserializer *self)
 
   xmlFree (version);
 
-  self->priv->r = xmlNewTextReaderFilename (biji_note_obj_get_path (n));
+  path = biji_note_obj_get_path (n);
+  self->priv->r = xmlNewTextReaderFilename (path);
+  g_free (path);
   biji_parse_file (self);
   xmlFreeDoc (doc);
 


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