]> err.no Git - libchamplain/commitdiff
Clean-up
authorPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Wed, 18 Feb 2009 18:30:42 +0000 (20:30 +0200)
committerPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Wed, 18 Feb 2009 18:30:42 +0000 (20:30 +0200)
(while trying to find a memory leak)

champlain/champlain-tile.c

index 9aaf1e82d2bb09e09dcd646a0ec2e5a6b1fd996f..2e6a3a8e45b49fe1a7d2c90fb38b1ec0aef6c18c 100644 (file)
@@ -544,59 +544,57 @@ file_loaded_cb (SoupSession *session,
       g_object_unref (tile);
       return;
     }
-  else
-    {
-      path = g_build_filename (g_get_user_cache_dir (),
-                                    CACHE_DIR,
-                                    map->name,
-                                    NULL);
 
-      if (g_mkdir_with_parents (path, 0700) == -1)
+  path = g_build_filename (g_get_user_cache_dir (),
+                                CACHE_DIR,
+                                map->name,
+                                NULL);
+
+  if (g_mkdir_with_parents (path, 0700) == -1)
+    {
+      if (errno != EEXIST)
         {
-          if (errno != EEXIST)
-            {
-              g_warning ("Unable to create the image cache: %s",
-                         g_strerror (errno));
-              g_object_unref (loader);
-            }
+          g_warning ("Unable to create the image cache: %s",
+                     g_strerror (errno));
+          g_object_unref (loader);
         }
+    }
 
-      map_filename = map->get_tile_filename(map, tile);
-      filename = g_build_filename (g_get_user_cache_dir (),
-                                    CACHE_DIR,
-                                    map->name,
-                                    map_filename,
-                                    NULL);
-
-      g_file_set_contents (filename,
-                           msg->response_body->data,
-                           msg->response_body->length,
-                           NULL);
-
-      GdkPixbuf* pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
-
-      ClutterActor *actor = clutter_texture_new();
-      clutter_texture_set_from_rgb_data (CLUTTER_TEXTURE (actor),
-          gdk_pixbuf_get_pixels (pixbuf),
-          gdk_pixbuf_get_has_alpha (pixbuf),
-          gdk_pixbuf_get_width (pixbuf),
-          gdk_pixbuf_get_height (pixbuf),
-          gdk_pixbuf_get_rowstride (pixbuf),
-          3, 0, NULL);
-      champlain_tile_set_actor (tile, actor);
+  map_filename = map->get_tile_filename(map, tile);
+  filename = g_build_filename (g_get_user_cache_dir (),
+                                CACHE_DIR,
+                                map->name,
+                                map_filename,
+                                NULL);
 
-      tile_set_position (map, tile);
+  g_file_set_contents (filename,
+                       msg->response_body->data,
+                       msg->response_body->length,
+                       NULL);
+
+  GdkPixbuf* pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
+
+  ClutterActor *actor = clutter_texture_new();
+  clutter_texture_set_from_rgb_data (CLUTTER_TEXTURE (actor),
+      gdk_pixbuf_get_pixels (pixbuf),
+      gdk_pixbuf_get_has_alpha (pixbuf),
+      gdk_pixbuf_get_width (pixbuf),
+      gdk_pixbuf_get_height (pixbuf),
+      gdk_pixbuf_get_rowstride (pixbuf),
+      3, 0, NULL);
+  champlain_tile_set_actor (tile, actor);
 
-      clutter_container_add (CLUTTER_CONTAINER (map->current_level->group), actor, NULL);
-      tile_setup_animation (tile);
+  tile_set_position (map, tile);
 
-      champlain_tile_set_state (tile, CHAMPLAIN_STATE_DONE);
-      g_object_unref (tile);
+  clutter_container_add (CLUTTER_CONTAINER (map->current_level->group), actor, NULL);
+  tile_setup_animation (tile);
 
-      g_object_unref (loader);
-      g_free (filename);
-      g_free (map_filename);
-    }
+  champlain_tile_set_state (tile, CHAMPLAIN_STATE_DONE);
+
+  g_object_unref (tile);
+  g_object_unref (loader); /* also frees the pixbuf */
+  g_free (filename);
+  g_free (map_filename);
   g_free (ptr);
 }
 
@@ -622,7 +620,7 @@ tile_load (Map* map, gint zoom_level, gint x, gint y, gboolean offline)
 
   if (g_file_test (filename, G_FILE_TEST_EXISTS))
     {
-      ClutterActor *actor = clutter_texture_new_from_file(filename, NULL);
+      ClutterActor *actor = clutter_texture_new_from_file (filename, NULL);
       champlain_tile_set_actor (tile, actor);
       tile_set_position (map, tile);