mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-05 06:50:17 +01:00
shared: clear destination pointer in nm_clear_*() functions first
It's slightly more correct to first clear the pointer location before invoking the destroy function. The destroy function might emit other callbacks, and at a certain point the pointer becomes dangling. Avoid this danling pointer, by first clearing the memory, and then destroing the instance.
This commit is contained in:
parent
f0442a47ed
commit
4cbe3eaaca
1 changed files with 21 additions and 9 deletions
|
|
@ -836,9 +836,12 @@ nm_g_object_unref (gpointer obj)
|
|||
static inline gboolean
|
||||
nm_clear_g_source (guint *id)
|
||||
{
|
||||
if (id && *id) {
|
||||
g_source_remove (*id);
|
||||
guint v;
|
||||
|
||||
if ( id
|
||||
&& (v = *id)) {
|
||||
*id = 0;
|
||||
g_source_remove (v);
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
|
|
@ -847,9 +850,12 @@ nm_clear_g_source (guint *id)
|
|||
static inline gboolean
|
||||
nm_clear_g_signal_handler (gpointer self, gulong *id)
|
||||
{
|
||||
if (id && *id) {
|
||||
g_signal_handler_disconnect (self, *id);
|
||||
gulong v;
|
||||
|
||||
if ( id
|
||||
&& (v = *id)) {
|
||||
*id = 0;
|
||||
g_signal_handler_disconnect (self, v);
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
|
|
@ -858,9 +864,12 @@ nm_clear_g_signal_handler (gpointer self, gulong *id)
|
|||
static inline gboolean
|
||||
nm_clear_g_variant (GVariant **variant)
|
||||
{
|
||||
if (variant && *variant) {
|
||||
g_variant_unref (*variant);
|
||||
GVariant *v;
|
||||
|
||||
if ( variant
|
||||
&& (v = *variant)) {
|
||||
*variant = NULL;
|
||||
g_variant_unref (v);
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
|
|
@ -869,10 +878,13 @@ nm_clear_g_variant (GVariant **variant)
|
|||
static inline gboolean
|
||||
nm_clear_g_cancellable (GCancellable **cancellable)
|
||||
{
|
||||
if (cancellable && *cancellable) {
|
||||
g_cancellable_cancel (*cancellable);
|
||||
g_object_unref (*cancellable);
|
||||
GCancellable *v;
|
||||
|
||||
if ( cancellable
|
||||
&& (v = *cancellable)) {
|
||||
*cancellable = NULL;
|
||||
g_cancellable_cancel (v);
|
||||
g_object_unref (v);
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue