[frogr] Fix segfault when no valid uris are passed via command line.



commit 044d929b389863924a87f56660b461533bbf9cc0
Author: Mario Sanchez Prada <msanchez igalia com>
Date:   Fri May 27 11:48:28 2011 +0200

    Fix segfault when no valid uris are passed via command line.
    
    Funny this is the first commit after the 0.5 release :-)

 src/frogr-picture-loader.c |   48 +++++++++++++++++++++++++------------------
 1 files changed, 28 insertions(+), 20 deletions(-)
---
diff --git a/src/frogr-picture-loader.c b/src/frogr-picture-loader.c
index 2d44ed2..0bd168d 100644
--- a/src/frogr-picture-loader.c
+++ b/src/frogr-picture-loader.c
@@ -186,46 +186,54 @@ _load_next_picture (FrogrPictureLoader *self)
     {
       gchar *file_uri = (gchar *)priv->current->data;
       GFile *gfile = g_file_new_for_uri (file_uri);
-      gboolean valid_mime = TRUE;
-
-#ifndef MAC_INTEGRATION
       GFileInfo *file_info;
-      const gchar *mime_type;
-      gint i;
+      gboolean valid_mime = TRUE;
 
-      /* Get file info */
+      /* Get file info (from this point on, use (file_info != NULL) as
+         a reliable way to know whether the file exists or not */
       file_info = g_file_query_info (gfile,
                                      G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
                                      G_FILE_QUERY_INFO_NONE,
                                      NULL,
                                      NULL);
+#ifndef MAC_INTEGRATION
+      const gchar *mime_type;
+      gint i;
 
-      /* Check mimetype (only when not in Mac OSX) */
-      mime_type = g_file_info_get_content_type (file_info);
-
-      valid_mime = FALSE;
-      for (i = 0; valid_mimetypes[i]; i++)
+      /* This can be NULL (e.g wrong parameter in the command line) */
+      if (file_info)
         {
-          if (g_str_equal (valid_mimetypes[i], mime_type))
+          /* Check mimetype (only when not in Mac OSX) */
+          mime_type = g_file_info_get_content_type (file_info);
+          valid_mime = FALSE;
+
+          if (mime_type)
             {
-              valid_mime = TRUE;
-              break;
+              for (i = 0; valid_mimetypes[i]; i++)
+                {
+                  if (g_str_equal (valid_mimetypes[i], mime_type))
+                    {
+                      valid_mime = TRUE;
+                      break;
+                    }
+                }
+
+              DEBUG ("Mime detected: %s)", mime_type);
             }
-        }
 
-      DEBUG ("Mime detected: %s)", mime_type);
-      g_object_unref (file_info);
+          g_object_unref (file_info);
+        }
 #endif
 
-      DEBUG ("Adding file %s", file_uri);
-
       /* Asynchronously load the picture if mime is valid */
-      if (valid_mime)
+      if (file_info && valid_mime)
         {
           g_file_load_contents_async (gfile,
                                       NULL,
                                       _load_next_picture_cb,
                                       self);
+
+          DEBUG ("Adding file %s", file_uri);
         }
       else
         {



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