Checked memory frees and added minor code fixes
authorSimón Pena <spenap@gmail.com>
Tue, 1 Jun 2010 18:56:59 +0000 (20:56 +0200)
committerSimón Pena <spenap@gmail.com>
Tue, 1 Jun 2010 18:56:59 +0000 (20:56 +0200)
* Added missing memory frees and object unrefs
* Reordered g_type_init () so that it gets called before
the thread_init. In glib >=2.24, g_type_init also prepares
the threads

src/maevies-service.c
src/mvs-minfo-provider.c
src/mvs-tmdb-movie.c
test/mvs-minfo-provider-test.c

index 739a6be..c2f71aa 100644 (file)
 int
 main (int argc, char **argv)
 {
-        MvsMInfoProviderService *service;
-        DBusGConnection *connection;
+        MvsMInfoProviderService *service = NULL;
+        DBusGConnection *connection = NULL;
         GError *error = NULL;
-        GMainLoop *loop;
+        GMainLoop *loop = NULL;
 
+        g_type_init ();
         if (!g_thread_supported ())
                 g_thread_init (NULL);
-        g_type_init ();
 
         connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
         if (connection == NULL) {
-                g_warning ("Unable to connect to dbus: %sn", error->message);
+                g_warning ("Unable to connect to dbus: %s", error->message);
                 g_error_free (error);
                 return -1;
         }
@@ -45,6 +45,9 @@ main (int argc, char **argv)
         g_main_loop_run (loop);
 
         g_object_unref (service);
+        g_main_loop_unref (loop);
+        dbus_g_connection_unref (connection);
+        g_error_free (error);
 
         return 0;
 }
index 6c9f446..af1fdf9 100644 (file)
@@ -149,9 +149,10 @@ create_tmdb_movie (xmlNodePtr node)
         xmlNodePtr cur_node = NULL;
         MvsTmdbMovie *movie_info = mvs_tmdb_movie_new ();
 
+        /* We use the loop to append each property to the movie object */
         for (cur_node = node; cur_node; cur_node = cur_node->next) {
                 if (cur_node->type == XML_ELEMENT_NODE) {
-                        gchar *value = xmlNodeGetContent (cur_node);
+                        const gchar *value = xmlNodeGetContent (cur_node);
 
                         g_object_set (movie_info, cur_node->name, value, NULL);
                 }
@@ -267,7 +268,7 @@ parse_json (const char *json_data, goffset length)
 }
 
 static void
-process_response (SoupSession *session, SoupMessage *message,
+process_response_cb (SoupSession *session, SoupMessage *message,
                     gpointer user_data)
 {
         MvsMInfoProvider *self = MVS_MINFO_PROVIDER (user_data);
@@ -294,6 +295,8 @@ process_response (SoupSession *session, SoupMessage *message,
         }
 
         g_signal_emit (self, signals[RESPONSE_RECEIVED], 0, list);
+
+        g_list_free (list);
 }
 
 static gchar *
@@ -345,7 +348,7 @@ mvs_minfo_provider_query (MvsMInfoProvider *self, MvsService service,
 
         if (message) {
                 soup_session_queue_message (session, message,
-                                process_response, self);
+                                process_response_cb, self);
                 message_queued = TRUE;
         }
 
index 36192fa..4d789a9 100644 (file)
@@ -372,7 +372,7 @@ set_property (gchar **property, const gchar *value)
         g_free (*property);
         *property = g_strdup (value);
 
-        return TRUE;
+        return *property != NULL;
 }
 
 gboolean
index 7f80c30..f05530d 100644 (file)
@@ -36,7 +36,7 @@ static GOptionEntry entries[] = {
 };
 
 static void
-response_received_callback (MvsMInfoProvider *minfo_provider, GList *list,
+response_received_cb (MvsMInfoProvider *minfo_provider, GList *list,
                             gpointer user_data)
 {
         GList *tmp = NULL;
@@ -72,18 +72,19 @@ main (int argc, char **argv)
 {
         MvsMInfoProvider *minfo_provider = NULL;
         GOptionContext *context = NULL;
-        GOptionGroup *gst_option_group = NULL;
         GError *error = NULL;
         MvsService service = MVS_SERVICE_TMDB;
 
         g_type_init ();
-
-        g_thread_init (NULL);
+        if (!g_thread_supported ())
+                g_thread_init (NULL);
 
         context = g_option_context_new (" - Tests data provider behavior");
         g_option_context_add_main_entries (context, entries, NULL);
         if (!g_option_context_parse (context, &argc, &argv, &error)) {
                 g_critical ("option parsing failed: %s", error->message);
+                g_error_free (error);
+                g_option_context_free (context);
                 return -1;
         }
 
@@ -94,7 +95,7 @@ main (int argc, char **argv)
 
         minfo_provider = mvs_minfo_provider_new ();
         g_signal_connect (minfo_provider, "response-received",
-                          G_CALLBACK (response_received_callback), NULL);
+                          G_CALLBACK (response_received_cb), NULL);
 
         loop = g_main_loop_new (NULL, FALSE);
 
@@ -102,8 +103,10 @@ main (int argc, char **argv)
                                   query);
 
         g_main_loop_run (loop);
+
         g_object_unref (minfo_provider);
         g_main_loop_unref (loop);
+        g_option_context_free (context);
 
         return 0;
 }