From 28440db6e006b544b4fd6b20fa27614873fae36e Mon Sep 17 00:00:00 2001 From: Michael Catanzaro Date: Sat, 30 Jun 2018 18:00:44 -0500 Subject: [PATCH 2/6] Fix use after free in xdg_mime_get_mime_type_for_file This upstreams the fix from https://codereview.chromium.org/1037023002 https://bugs.freedesktop.org/show_bug.cgi?id=100733 --- src/xdgmime.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/xdgmime.c b/src/xdgmime.c index c7b16bb..70c99bc 100644 --- a/src/xdgmime.c +++ b/src/xdgmime.c @@ -558,13 +558,13 @@ xdg_mime_get_mime_type_for_file (const char *file_name, mime_type = _xdg_mime_magic_lookup_data (global_magic, data, bytes_read, NULL, mime_types, n); - free (data); fclose (file); - if (mime_type) - return mime_type; + if (!mime_type) + mime_type = _xdg_binary_or_text_fallback (data, bytes_read); - return _xdg_binary_or_text_fallback(data, bytes_read); + free (data); + return mime_type; } const char * -- 2.17.1