mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-26 05:56:14 +01:00
Merge branch '2310-xdgmime-leaks' into 'main'
gcontenttype: Ignore intentional one-time leaks from xdgmime Closes #2310 See merge request GNOME/glib!2268
This commit is contained in:
commit
7be79cb840
@ -32,6 +32,7 @@
|
|||||||
#include "gfileenumerator.h"
|
#include "gfileenumerator.h"
|
||||||
#include "gfileinfo.h"
|
#include "gfileinfo.h"
|
||||||
#include "glibintl.h"
|
#include "glibintl.h"
|
||||||
|
#include "glib-private.h"
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -57,7 +58,12 @@
|
|||||||
|
|
||||||
static void tree_magic_schedule_reload (void);
|
static void tree_magic_schedule_reload (void);
|
||||||
|
|
||||||
/* We lock this mutex whenever we modify global state in this module. */
|
/* We lock this mutex whenever we modify global state in this module.
|
||||||
|
* Taking and releasing this lock should always be associated with a pair of
|
||||||
|
* g_begin_ignore_leaks()/g_end_ignore_leaks() calls, as any call into xdgmime
|
||||||
|
* could trigger xdg_mime_init(), which makes a number of one-time allocations
|
||||||
|
* which GLib can never free as it doesn’t know when is suitable to call
|
||||||
|
* xdg_mime_shutdown(). */
|
||||||
G_LOCK_DEFINE_STATIC (gio_xdgmime);
|
G_LOCK_DEFINE_STATIC (gio_xdgmime);
|
||||||
|
|
||||||
gsize
|
gsize
|
||||||
@ -66,7 +72,9 @@ _g_unix_content_type_get_sniff_len (void)
|
|||||||
gsize size;
|
gsize size;
|
||||||
|
|
||||||
G_LOCK (gio_xdgmime);
|
G_LOCK (gio_xdgmime);
|
||||||
|
g_begin_ignore_leaks ();
|
||||||
size = xdg_mime_get_max_buffer_extents ();
|
size = xdg_mime_get_max_buffer_extents ();
|
||||||
|
g_end_ignore_leaks ();
|
||||||
G_UNLOCK (gio_xdgmime);
|
G_UNLOCK (gio_xdgmime);
|
||||||
|
|
||||||
return size;
|
return size;
|
||||||
@ -78,7 +86,9 @@ _g_unix_content_type_unalias (const gchar *type)
|
|||||||
gchar *res;
|
gchar *res;
|
||||||
|
|
||||||
G_LOCK (gio_xdgmime);
|
G_LOCK (gio_xdgmime);
|
||||||
|
g_begin_ignore_leaks ();
|
||||||
res = g_strdup (xdg_mime_unalias_mime_type (type));
|
res = g_strdup (xdg_mime_unalias_mime_type (type));
|
||||||
|
g_end_ignore_leaks ();
|
||||||
G_UNLOCK (gio_xdgmime);
|
G_UNLOCK (gio_xdgmime);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
@ -95,6 +105,7 @@ _g_unix_content_type_get_parents (const gchar *type)
|
|||||||
array = g_ptr_array_new ();
|
array = g_ptr_array_new ();
|
||||||
|
|
||||||
G_LOCK (gio_xdgmime);
|
G_LOCK (gio_xdgmime);
|
||||||
|
g_begin_ignore_leaks ();
|
||||||
|
|
||||||
umime = xdg_mime_unalias_mime_type (type);
|
umime = xdg_mime_unalias_mime_type (type);
|
||||||
|
|
||||||
@ -106,6 +117,7 @@ _g_unix_content_type_get_parents (const gchar *type)
|
|||||||
|
|
||||||
free (parents);
|
free (parents);
|
||||||
|
|
||||||
|
g_end_ignore_leaks ();
|
||||||
G_UNLOCK (gio_xdgmime);
|
G_UNLOCK (gio_xdgmime);
|
||||||
|
|
||||||
g_ptr_array_add (array, NULL);
|
g_ptr_array_add (array, NULL);
|
||||||
@ -233,7 +245,9 @@ g_content_type_equals (const gchar *type1,
|
|||||||
g_return_val_if_fail (type2 != NULL, FALSE);
|
g_return_val_if_fail (type2 != NULL, FALSE);
|
||||||
|
|
||||||
G_LOCK (gio_xdgmime);
|
G_LOCK (gio_xdgmime);
|
||||||
|
g_begin_ignore_leaks ();
|
||||||
res = xdg_mime_mime_type_equal (type1, type2);
|
res = xdg_mime_mime_type_equal (type1, type2);
|
||||||
|
g_end_ignore_leaks ();
|
||||||
G_UNLOCK (gio_xdgmime);
|
G_UNLOCK (gio_xdgmime);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
@ -259,7 +273,9 @@ g_content_type_is_a (const gchar *type,
|
|||||||
g_return_val_if_fail (supertype != NULL, FALSE);
|
g_return_val_if_fail (supertype != NULL, FALSE);
|
||||||
|
|
||||||
G_LOCK (gio_xdgmime);
|
G_LOCK (gio_xdgmime);
|
||||||
|
g_begin_ignore_leaks ();
|
||||||
res = xdg_mime_mime_type_subclass (type, supertype);
|
res = xdg_mime_mime_type_subclass (type, supertype);
|
||||||
|
g_end_ignore_leaks ();
|
||||||
G_UNLOCK (gio_xdgmime);
|
G_UNLOCK (gio_xdgmime);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
@ -472,7 +488,9 @@ g_content_type_get_description (const gchar *type)
|
|||||||
g_return_val_if_fail (type != NULL, NULL);
|
g_return_val_if_fail (type != NULL, NULL);
|
||||||
|
|
||||||
G_LOCK (gio_xdgmime);
|
G_LOCK (gio_xdgmime);
|
||||||
|
g_begin_ignore_leaks ();
|
||||||
type = xdg_mime_unalias_mime_type (type);
|
type = xdg_mime_unalias_mime_type (type);
|
||||||
|
g_end_ignore_leaks ();
|
||||||
|
|
||||||
if (type_comment_cache == NULL)
|
if (type_comment_cache == NULL)
|
||||||
type_comment_cache = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
|
type_comment_cache = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
|
||||||
@ -528,7 +546,9 @@ g_content_type_get_icon_internal (const gchar *type,
|
|||||||
g_return_val_if_fail (type != NULL, NULL);
|
g_return_val_if_fail (type != NULL, NULL);
|
||||||
|
|
||||||
G_LOCK (gio_xdgmime);
|
G_LOCK (gio_xdgmime);
|
||||||
|
g_begin_ignore_leaks ();
|
||||||
xdg_icon = xdg_mime_get_icon (type);
|
xdg_icon = xdg_mime_get_icon (type);
|
||||||
|
g_end_ignore_leaks ();
|
||||||
G_UNLOCK (gio_xdgmime);
|
G_UNLOCK (gio_xdgmime);
|
||||||
|
|
||||||
if (xdg_icon)
|
if (xdg_icon)
|
||||||
@ -619,7 +639,9 @@ g_content_type_get_generic_icon_name (const gchar *type)
|
|||||||
g_return_val_if_fail (type != NULL, NULL);
|
g_return_val_if_fail (type != NULL, NULL);
|
||||||
|
|
||||||
G_LOCK (gio_xdgmime);
|
G_LOCK (gio_xdgmime);
|
||||||
|
g_begin_ignore_leaks ();
|
||||||
xdg_icon_name = xdg_mime_get_generic_icon (type);
|
xdg_icon_name = xdg_mime_get_generic_icon (type);
|
||||||
|
g_end_ignore_leaks ();
|
||||||
G_UNLOCK (gio_xdgmime);
|
G_UNLOCK (gio_xdgmime);
|
||||||
|
|
||||||
if (!xdg_icon_name)
|
if (!xdg_icon_name)
|
||||||
@ -703,8 +725,10 @@ g_content_type_from_mime_type (const gchar *mime_type)
|
|||||||
g_return_val_if_fail (mime_type != NULL, NULL);
|
g_return_val_if_fail (mime_type != NULL, NULL);
|
||||||
|
|
||||||
G_LOCK (gio_xdgmime);
|
G_LOCK (gio_xdgmime);
|
||||||
|
g_begin_ignore_leaks ();
|
||||||
/* mime type and content type are same on unixes */
|
/* mime type and content type are same on unixes */
|
||||||
umime = g_strdup (xdg_mime_unalias_mime_type (mime_type));
|
umime = g_strdup (xdg_mime_unalias_mime_type (mime_type));
|
||||||
|
g_end_ignore_leaks ();
|
||||||
G_UNLOCK (gio_xdgmime);
|
G_UNLOCK (gio_xdgmime);
|
||||||
|
|
||||||
return umime;
|
return umime;
|
||||||
@ -751,6 +775,7 @@ g_content_type_guess (const gchar *filename,
|
|||||||
g_return_val_if_fail (data_size != (gsize) -1, g_strdup (XDG_MIME_TYPE_UNKNOWN));
|
g_return_val_if_fail (data_size != (gsize) -1, g_strdup (XDG_MIME_TYPE_UNKNOWN));
|
||||||
|
|
||||||
G_LOCK (gio_xdgmime);
|
G_LOCK (gio_xdgmime);
|
||||||
|
g_begin_ignore_leaks ();
|
||||||
|
|
||||||
if (filename)
|
if (filename)
|
||||||
{
|
{
|
||||||
@ -775,6 +800,7 @@ g_content_type_guess (const gchar *filename,
|
|||||||
if (n_name_mimetypes == 1)
|
if (n_name_mimetypes == 1)
|
||||||
{
|
{
|
||||||
gchar *s = g_strdup (name_mimetypes[0]);
|
gchar *s = g_strdup (name_mimetypes[0]);
|
||||||
|
g_end_ignore_leaks ();
|
||||||
G_UNLOCK (gio_xdgmime);
|
G_UNLOCK (gio_xdgmime);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
@ -843,6 +869,7 @@ g_content_type_guess (const gchar *filename,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_end_ignore_leaks ();
|
||||||
G_UNLOCK (gio_xdgmime);
|
G_UNLOCK (gio_xdgmime);
|
||||||
|
|
||||||
return mimetype;
|
return mimetype;
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
#include <gio/gio.h>
|
#include <gio/gio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "glib/glib-private.h"
|
|
||||||
|
|
||||||
#define g_assert_content_type_equals(s1, s2) \
|
#define g_assert_content_type_equals(s1, s2) \
|
||||||
do { \
|
do { \
|
||||||
const char *__s1 = (s1), *__s2 = (s2); \
|
const char *__s1 = (s1), *__s2 = (s2); \
|
||||||
@ -18,9 +16,6 @@
|
|||||||
static void
|
static void
|
||||||
test_guess (void)
|
test_guess (void)
|
||||||
{
|
{
|
||||||
#ifdef _GLIB_ADDRESS_SANITIZER
|
|
||||||
g_test_incomplete ("FIXME: Leaks xdgmime internal data, see glib#2310");
|
|
||||||
#else
|
|
||||||
gchar *res;
|
gchar *res;
|
||||||
gchar *expected;
|
gchar *expected;
|
||||||
gchar *existing_directory;
|
gchar *existing_directory;
|
||||||
@ -131,15 +126,11 @@ test_guess (void)
|
|||||||
g_assert_false (uncertain);
|
g_assert_false (uncertain);
|
||||||
g_free (res);
|
g_free (res);
|
||||||
g_free (expected);
|
g_free (expected);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_unknown (void)
|
test_unknown (void)
|
||||||
{
|
{
|
||||||
#ifdef _GLIB_ADDRESS_SANITIZER
|
|
||||||
g_test_incomplete ("FIXME: Leaks xdgmime internal data, see glib#2310");
|
|
||||||
#else
|
|
||||||
gchar *unknown;
|
gchar *unknown;
|
||||||
gchar *str;
|
gchar *str;
|
||||||
|
|
||||||
@ -149,15 +140,11 @@ test_unknown (void)
|
|||||||
g_assert_cmpstr (str, ==, "application/octet-stream");
|
g_assert_cmpstr (str, ==, "application/octet-stream");
|
||||||
g_free (str);
|
g_free (str);
|
||||||
g_free (unknown);
|
g_free (unknown);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_subtype (void)
|
test_subtype (void)
|
||||||
{
|
{
|
||||||
#ifdef _GLIB_ADDRESS_SANITIZER
|
|
||||||
g_test_incomplete ("FIXME: Leaks xdgmime internal data, see glib#2310");
|
|
||||||
#else
|
|
||||||
gchar *plain;
|
gchar *plain;
|
||||||
gchar *xml;
|
gchar *xml;
|
||||||
|
|
||||||
@ -169,7 +156,6 @@ test_subtype (void)
|
|||||||
|
|
||||||
g_free (plain);
|
g_free (plain);
|
||||||
g_free (xml);
|
g_free (xml);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gint
|
static gint
|
||||||
@ -183,10 +169,6 @@ find_mime (gconstpointer a, gconstpointer b)
|
|||||||
static void
|
static void
|
||||||
test_list (void)
|
test_list (void)
|
||||||
{
|
{
|
||||||
#ifdef _GLIB_ADDRESS_SANITIZER
|
|
||||||
g_test_incomplete ("FIXME: Leaks xdgmime internal data, see glib#2310");
|
|
||||||
(void) find_mime;
|
|
||||||
#else
|
|
||||||
GList *types;
|
GList *types;
|
||||||
gchar *plain;
|
gchar *plain;
|
||||||
gchar *xml;
|
gchar *xml;
|
||||||
@ -211,15 +193,11 @@ test_list (void)
|
|||||||
|
|
||||||
g_free (plain);
|
g_free (plain);
|
||||||
g_free (xml);
|
g_free (xml);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_executable (void)
|
test_executable (void)
|
||||||
{
|
{
|
||||||
#ifdef _GLIB_ADDRESS_SANITIZER
|
|
||||||
g_test_incomplete ("FIXME: Leaks xdgmime internal data, see glib#2310");
|
|
||||||
#else
|
|
||||||
gchar *type;
|
gchar *type;
|
||||||
|
|
||||||
type = g_content_type_from_mime_type ("application/x-executable");
|
type = g_content_type_from_mime_type ("application/x-executable");
|
||||||
@ -233,15 +211,11 @@ test_executable (void)
|
|||||||
type = g_content_type_from_mime_type ("image/png");
|
type = g_content_type_from_mime_type ("image/png");
|
||||||
g_assert_false (g_content_type_can_be_executable (type));
|
g_assert_false (g_content_type_can_be_executable (type));
|
||||||
g_free (type);
|
g_free (type);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_description (void)
|
test_description (void)
|
||||||
{
|
{
|
||||||
#ifdef _GLIB_ADDRESS_SANITIZER
|
|
||||||
g_test_incomplete ("FIXME: Leaks xdgmime internal data, see glib#2310");
|
|
||||||
#else
|
|
||||||
gchar *type;
|
gchar *type;
|
||||||
gchar *desc;
|
gchar *desc;
|
||||||
|
|
||||||
@ -251,15 +225,11 @@ test_description (void)
|
|||||||
|
|
||||||
g_free (desc);
|
g_free (desc);
|
||||||
g_free (type);
|
g_free (type);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_icon (void)
|
test_icon (void)
|
||||||
{
|
{
|
||||||
#ifdef _GLIB_ADDRESS_SANITIZER
|
|
||||||
g_test_incomplete ("FIXME: Leaks xdgmime internal data, see glib#2310");
|
|
||||||
#else
|
|
||||||
gchar *type;
|
gchar *type;
|
||||||
GIcon *icon;
|
GIcon *icon;
|
||||||
|
|
||||||
@ -296,15 +266,12 @@ test_icon (void)
|
|||||||
}
|
}
|
||||||
g_object_unref (icon);
|
g_object_unref (icon);
|
||||||
g_free (type);
|
g_free (type);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_symbolic_icon (void)
|
test_symbolic_icon (void)
|
||||||
{
|
{
|
||||||
#ifdef _GLIB_ADDRESS_SANITIZER
|
#ifndef G_OS_WIN32
|
||||||
g_test_incomplete ("FIXME: Leaks xdgmime internal data, see glib#2310");
|
|
||||||
#elif !defined(G_OS_WIN32)
|
|
||||||
gchar *type;
|
gchar *type;
|
||||||
GIcon *icon;
|
GIcon *icon;
|
||||||
|
|
||||||
@ -352,9 +319,6 @@ test_symbolic_icon (void)
|
|||||||
static void
|
static void
|
||||||
test_tree (void)
|
test_tree (void)
|
||||||
{
|
{
|
||||||
#ifdef _GLIB_ADDRESS_SANITIZER
|
|
||||||
g_test_incomplete ("FIXME: Leaks xdgmime internal data, see glib#2310");
|
|
||||||
#else
|
|
||||||
const gchar *tests[] = {
|
const gchar *tests[] = {
|
||||||
"x-content/image-dcf",
|
"x-content/image-dcf",
|
||||||
"x-content/unix-software",
|
"x-content/unix-software",
|
||||||
@ -379,15 +343,11 @@ test_tree (void)
|
|||||||
g_strfreev (types);
|
g_strfreev (types);
|
||||||
g_object_unref (file);
|
g_object_unref (file);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_type_is_a_special_case (void)
|
test_type_is_a_special_case (void)
|
||||||
{
|
{
|
||||||
#ifdef _GLIB_ADDRESS_SANITIZER
|
|
||||||
g_test_incomplete ("FIXME: Leaks xdgmime internal data, see glib#2310");
|
|
||||||
#else
|
|
||||||
gboolean res;
|
gboolean res;
|
||||||
|
|
||||||
g_test_bug ("https://bugzilla.gnome.org/show_bug.cgi?id=782311");
|
g_test_bug ("https://bugzilla.gnome.org/show_bug.cgi?id=782311");
|
||||||
@ -399,15 +359,11 @@ test_type_is_a_special_case (void)
|
|||||||
res = g_content_type_is_a ("anything", "application/octet-stream");
|
res = g_content_type_is_a ("anything", "application/octet-stream");
|
||||||
g_assert_true (res);
|
g_assert_true (res);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_guess_svg_from_data (void)
|
test_guess_svg_from_data (void)
|
||||||
{
|
{
|
||||||
#ifdef _GLIB_ADDRESS_SANITIZER
|
|
||||||
g_test_incomplete ("FIXME: Leaks xdgmime internal data, see glib#2310");
|
|
||||||
#else
|
|
||||||
const gchar svgfilecontent[] = "<svg xmlns=\"http://www.w3.org/2000/svg\"\
|
const gchar svgfilecontent[] = "<svg xmlns=\"http://www.w3.org/2000/svg\"\
|
||||||
xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n\
|
xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n\
|
||||||
<rect x=\"10\" y=\"10\" height=\"100\" width=\"100\"\n\
|
<rect x=\"10\" y=\"10\" height=\"100\" width=\"100\"\n\
|
||||||
@ -426,15 +382,12 @@ test_guess_svg_from_data (void)
|
|||||||
#endif
|
#endif
|
||||||
g_assert_false (uncertain);
|
g_assert_false (uncertain);
|
||||||
g_free (res);
|
g_free (res);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_mime_from_content (void)
|
test_mime_from_content (void)
|
||||||
{
|
{
|
||||||
#ifdef _GLIB_ADDRESS_SANITIZER
|
#ifdef __APPLE__
|
||||||
g_test_incomplete ("FIXME: Leaks xdgmime internal data, see glib#2310");
|
|
||||||
#elif defined(__APPLE__)
|
|
||||||
gchar *mime_type;
|
gchar *mime_type;
|
||||||
mime_type = g_content_type_get_mime_type ("com.microsoft.bmp");
|
mime_type = g_content_type_get_mime_type ("com.microsoft.bmp");
|
||||||
g_assert_cmpstr (mime_type, ==, "image/bmp");
|
g_assert_cmpstr (mime_type, ==, "image/bmp");
|
||||||
|
@ -84,6 +84,37 @@ g_ignore_strv_leak (GStrv strv)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* g_begin_ignore_leaks:
|
||||||
|
*
|
||||||
|
* Tell AddressSanitizer and similar tools to ignore all leaks from this point
|
||||||
|
* onwards, until g_end_ignore_leaks() is called.
|
||||||
|
*
|
||||||
|
* Try to use g_ignore_leak() where possible to target deliberate leaks more
|
||||||
|
* specifically.
|
||||||
|
*/
|
||||||
|
static inline void
|
||||||
|
g_begin_ignore_leaks (void)
|
||||||
|
{
|
||||||
|
#ifdef _GLIB_ADDRESS_SANITIZER
|
||||||
|
__lsan_disable ();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* g_end_ignore_leaks:
|
||||||
|
*
|
||||||
|
* Start ignoring leaks again; this must be paired with a previous call to
|
||||||
|
* g_begin_ignore_leaks().
|
||||||
|
*/
|
||||||
|
static inline void
|
||||||
|
g_end_ignore_leaks (void)
|
||||||
|
{
|
||||||
|
#ifdef _GLIB_ADDRESS_SANITIZER
|
||||||
|
__lsan_enable ();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
GMainContext * g_get_worker_context (void);
|
GMainContext * g_get_worker_context (void);
|
||||||
gboolean g_check_setuid (void);
|
gboolean g_check_setuid (void);
|
||||||
GMainContext * g_main_context_new_with_next_id (guint next_id);
|
GMainContext * g_main_context_new_with_next_id (guint next_id);
|
||||||
|
Loading…
Reference in New Issue
Block a user