mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-23 10:42:11 +01:00
gobject: Sink floating pspecs if adding them to a class fails
This may fix Coverity assuming that pspecs are leaked, which is causing tens and tens of false positives in the latest Coverity reports for GLib. Ensure that the pspecs are sunk (if floating) even if adding them to the class fails (due to validation failure or an identically named property already existing). Signed-off-by: Philip Withnall <pwithnall@endlessos.org> (cherry-picked from commit 8f7df344b636d5fda3d05560f5142d5d8515662a)
This commit is contained in:
parent
af10448a05
commit
cd657d692d
@ -572,22 +572,25 @@ g_object_do_class_init (GObjectClass *class)
|
|||||||
g_type_add_interface_check (NULL, object_interface_check_properties);
|
g_type_add_interface_check (NULL, object_interface_check_properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Sinks @pspec if it’s a floating ref. */
|
||||||
static inline gboolean
|
static inline gboolean
|
||||||
install_property_internal (GType g_type,
|
install_property_internal (GType g_type,
|
||||||
guint property_id,
|
guint property_id,
|
||||||
GParamSpec *pspec)
|
GParamSpec *pspec)
|
||||||
{
|
{
|
||||||
|
g_param_spec_ref_sink (pspec);
|
||||||
|
|
||||||
if (g_param_spec_pool_lookup (pspec_pool, pspec->name, g_type, FALSE))
|
if (g_param_spec_pool_lookup (pspec_pool, pspec->name, g_type, FALSE))
|
||||||
{
|
{
|
||||||
g_warning ("When installing property: type '%s' already has a property named '%s'",
|
g_warning ("When installing property: type '%s' already has a property named '%s'",
|
||||||
g_type_name (g_type),
|
g_type_name (g_type),
|
||||||
pspec->name);
|
pspec->name);
|
||||||
|
g_param_spec_unref (pspec);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_param_spec_ref_sink (pspec);
|
|
||||||
PARAM_SPEC_SET_PARAM_ID (pspec, property_id);
|
PARAM_SPEC_SET_PARAM_ID (pspec, property_id);
|
||||||
g_param_spec_pool_insert (pspec_pool, pspec, g_type);
|
g_param_spec_pool_insert (pspec_pool, g_steal_pointer (&pspec), g_type);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -608,6 +611,7 @@ validate_pspec_to_install (GParamSpec *pspec)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Sinks @pspec if it’s a floating ref. */
|
||||||
static gboolean
|
static gboolean
|
||||||
validate_and_install_class_property (GObjectClass *class,
|
validate_and_install_class_property (GObjectClass *class,
|
||||||
GType oclass_type,
|
GType oclass_type,
|
||||||
@ -616,7 +620,11 @@ validate_and_install_class_property (GObjectClass *class,
|
|||||||
GParamSpec *pspec)
|
GParamSpec *pspec)
|
||||||
{
|
{
|
||||||
if (!validate_pspec_to_install (pspec))
|
if (!validate_pspec_to_install (pspec))
|
||||||
|
{
|
||||||
|
g_param_spec_ref_sink (pspec);
|
||||||
|
g_param_spec_unref (pspec);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (pspec->flags & G_PARAM_WRITABLE)
|
if (pspec->flags & G_PARAM_WRITABLE)
|
||||||
g_return_val_if_fail (class->set_property != NULL, FALSE);
|
g_return_val_if_fail (class->set_property != NULL, FALSE);
|
||||||
@ -824,7 +832,11 @@ g_object_interface_install_property (gpointer g_iface,
|
|||||||
g_return_if_fail (!G_IS_PARAM_SPEC_OVERRIDE (pspec)); /* paranoid */
|
g_return_if_fail (!G_IS_PARAM_SPEC_OVERRIDE (pspec)); /* paranoid */
|
||||||
|
|
||||||
if (!validate_pspec_to_install (pspec))
|
if (!validate_pspec_to_install (pspec))
|
||||||
|
{
|
||||||
|
g_param_spec_ref_sink (pspec);
|
||||||
|
g_param_spec_unref (pspec);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
(void) install_property_internal (iface_class->g_type, 0, pspec);
|
(void) install_property_internal (iface_class->g_type, 0, pspec);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user