From eb04fe50682005da212c0c796ea3fa589d744212 Mon Sep 17 00:00:00 2001 From: Christian Persch Date: Sun, 15 Feb 2009 13:51:42 +0000 Subject: NULL safety. (get_mime_type_from_data): Return the MIME type, not the * libdocument/ev-file-helpers.c: (get_mime_type_from_uri): NULL safety. (get_mime_type_from_data): Return the MIME type, not the content type. svn path=/trunk/; revision=3440 --- (limited to 'libdocument') diff --git a/libdocument/ev-file-helpers.c b/libdocument/ev-file-helpers.c index 8811f25..7659562 100644 --- a/libdocument/ev-file-helpers.c +++ b/libdocument/ev-file-helpers.c @@ -212,9 +212,9 @@ ev_xfer_uri_simple (const char *from, static gchar * get_mime_type_from_uri (const gchar *uri, GError **error) { - GFile *file; - GFileInfo *file_info; - gchar *mime_type; + GFile *file; + GFileInfo *file_info; + const gchar *content_type; file = g_file_new_for_uri (uri); file_info = g_file_query_info (file, @@ -225,11 +225,13 @@ get_mime_type_from_uri (const gchar *uri, GError **error) if (file_info == NULL) return NULL; - mime_type = g_content_type_get_mime_type ( - g_file_info_get_content_type (file_info)); + content_type = g_file_info_get_content_type (file_info); g_object_unref (file_info); - return mime_type; + if (!content_type) + return NULL; + + return g_content_type_get_mime_type (content_type); } static gchar * @@ -240,6 +242,7 @@ get_mime_type_from_data (const gchar *uri, GError **error) gssize size_read; guchar buffer[1024]; gboolean retval; + gchar *content_type, *mime_type; file = g_file_new_for_uri (uri); @@ -264,9 +267,15 @@ get_mime_type_from_data (const gchar *uri, GError **error) if (!retval) return NULL; - return g_content_type_guess (NULL, /* no filename */ - buffer, size_read, - NULL); + content_type = g_content_type_guess (NULL, /* no filename */ + buffer, size_read, + NULL); + if (!content_type) + return NULL; + + mime_type = g_content_type_get_mime_type (content_type); + g_free (content_type); + return mime_type; } /** -- cgit v0.9.1