mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-02 07:36:17 +01:00
GVariant: add preconditions to ref. counting functions
These prevent GVariants from accidentally being brought back to life after being freed, and should make it easier to track down ref. counting issues. Closes: bgo#665184
This commit is contained in:
parent
190645bcc4
commit
22da18fa70
@ -619,6 +619,9 @@ g_variant_is_trusted (GVariant *value)
|
||||
void
|
||||
g_variant_unref (GVariant *value)
|
||||
{
|
||||
g_return_if_fail (value != NULL);
|
||||
g_return_if_fail (value->ref_count > 0);
|
||||
|
||||
if (g_atomic_int_dec_and_test (&value->ref_count))
|
||||
{
|
||||
if G_UNLIKELY (value->state & STATE_LOCKED)
|
||||
@ -652,6 +655,9 @@ g_variant_unref (GVariant *value)
|
||||
GVariant *
|
||||
g_variant_ref (GVariant *value)
|
||||
{
|
||||
g_return_val_if_fail (value != NULL, NULL);
|
||||
g_return_val_if_fail (value->ref_count > 0, NULL);
|
||||
|
||||
g_atomic_int_inc (&value->ref_count);
|
||||
|
||||
return value;
|
||||
@ -691,6 +697,9 @@ g_variant_ref (GVariant *value)
|
||||
GVariant *
|
||||
g_variant_ref_sink (GVariant *value)
|
||||
{
|
||||
g_return_val_if_fail (value != NULL, NULL);
|
||||
g_return_val_if_fail (value->ref_count > 0, NULL);
|
||||
|
||||
g_variant_lock (value);
|
||||
|
||||
if (~value->state & STATE_FLOATING)
|
||||
@ -746,6 +755,7 @@ GVariant *
|
||||
g_variant_take_ref (GVariant *value)
|
||||
{
|
||||
g_return_val_if_fail (value != NULL, NULL);
|
||||
g_return_val_if_fail (value->ref_count > 0, NULL);
|
||||
|
||||
g_atomic_int_and (&value->state, ~STATE_FLOATING);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user