Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix pending call unref convention for dbus_send() helper functions
Legacy way of dealing with asynchronous dbus method calls in mce was to
a) leave one extra ref to pending call when issuing the method call
b) call dbus_pending_call_unref() from handler callback
Which is problematic since (b) does not happen if the pending call is
canceled.

Now the extra reference is cleared after it is no longer needed and
calls to dbus_pending_call_unref() from all related handler callbacks
are removed.
  • Loading branch information
spiiroin committed Aug 25, 2014
1 parent a348788 commit 7ea70a0
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 24 deletions.
15 changes: 3 additions & 12 deletions mce-dbus.c
Expand Up @@ -499,16 +499,6 @@ dbus_send_message_with_reply_handler(DBusMessage *const msg,
if( ppc )
*ppc = dbus_pending_call_ref(pc);

/* FIXME: After succesful set_notify the notification holds a ref
* to the pending call and we could and should always unref
* within this function. BUT, since the currently existing
* callbacks do call unref, we can't do that before fixing
* each and every one of them...
*
* Instead we do not unref on success, i.e. after getting here
*/
pc = 0;

/* Ownership of user_data passed on */
user_free = 0, user_data = 0;

Expand All @@ -519,6 +509,9 @@ dbus_send_message_with_reply_handler(DBusMessage *const msg,
if( user_free )
user_free(user_data);

/* If notification was set succesfully above, it will hold
* one reference to the pending call until a) the callback function
* gets called, or b) the pending call is canceled */
if( pc )
dbus_pending_call_unref(pc);

Expand Down Expand Up @@ -2529,7 +2522,6 @@ static void mce_dbus_ident_query_pid_cb(DBusPendingCall *pc, void *aptr)

EXIT:
if( rsp ) dbus_message_unref(rsp);
if( pc ) dbus_pending_call_unref(pc);
dbus_error_free(&err);

return;
Expand Down Expand Up @@ -2819,7 +2811,6 @@ mce_dbus_get_pid_async_cb(DBusPendingCall *pc, void *aptr)
EXIT:

if( rsp ) dbus_message_unref(rsp);
if( pc ) dbus_pending_call_unref(pc);
dbus_error_free(&err);

return;
Expand Down
6 changes: 0 additions & 6 deletions mce-sensorfw.c
Expand Up @@ -1325,7 +1325,6 @@ sfw_reporting_value_cb(DBusPendingCall *pc, void *aptr)
sfw_plugin_get_sensor_name(self->rep_plugin));

if( rsp ) dbus_message_unref(rsp);
if( pc ) dbus_pending_call_unref(pc);
dbus_error_free(&err);

return;
Expand Down Expand Up @@ -1381,7 +1380,6 @@ sfw_reporting_change_cb(DBusPendingCall *pc, void *aptr)
}

if( rsp ) dbus_message_unref(rsp);
if( pc ) dbus_pending_call_unref(pc);
dbus_error_free(&err);

return;
Expand Down Expand Up @@ -1602,7 +1600,6 @@ sfw_override_start_cb(DBusPendingCall *pc, void *aptr)
}

if( rsp ) dbus_message_unref(rsp);
if( pc ) dbus_pending_call_unref(pc);
dbus_error_free(&err);

return;
Expand Down Expand Up @@ -2243,7 +2240,6 @@ sfw_session_start_cb(DBusPendingCall *pc, void *aptr)
sfw_session_trans(self, SESSION_ERROR);

if( rsp ) dbus_message_unref(rsp);
if( pc ) dbus_pending_call_unref(pc);
dbus_error_free(&err);

return;
Expand Down Expand Up @@ -2552,7 +2548,6 @@ sfw_plugin_load_cb(DBusPendingCall *pc, void *aptr)
}

if( rsp ) dbus_message_unref(rsp);
if( pc ) dbus_pending_call_unref(pc);
dbus_error_free(&err);

return;
Expand Down Expand Up @@ -2778,7 +2773,6 @@ sfw_service_query_cb(DBusPendingCall *pc, void *aptr)
}

if( rsp ) dbus_message_unref(rsp);
if( pc ) dbus_pending_call_unref(pc);
dbus_error_free(&err);
}

Expand Down
1 change: 0 additions & 1 deletion modules/battery-upower.c
Expand Up @@ -937,7 +937,6 @@ static void xup_enumerate_devices_cb(DBusPendingCall *pc, void *aptr)

dbus_free_string_array(vec);
if( rsp ) dbus_message_unref(rsp);
dbus_pending_call_unref(pc);
dbus_error_free(&err);
}

Expand Down
2 changes: 0 additions & 2 deletions modules/callstate.c
Expand Up @@ -932,7 +932,6 @@ xofono_get_modems_cb(DBusPendingCall *pc, void *aptr)
EXIT:
mce_log(LL_DEBUG, "added %d modems", cnt);
if( rsp ) dbus_message_unref(rsp);
dbus_pending_call_unref(pc);
dbus_error_free(&err);
}

Expand Down Expand Up @@ -1140,7 +1139,6 @@ xofono_name_owner_get_cb(DBusPendingCall *pc, void *user_data)

EXIT:
if( rsp ) dbus_message_unref(rsp);
if( pc ) dbus_pending_call_unref(pc);
dbus_error_free(&err);
}

Expand Down
2 changes: 0 additions & 2 deletions modules/packagekit.c
Expand Up @@ -267,7 +267,6 @@ xpkgkit_get_properties_cb(DBusPendingCall *pc, void *aptr)

EXIT:
if( rsp ) dbus_message_unref(rsp);
if( pc ) dbus_pending_call_unref(pc);
dbus_error_free(&err);
}

Expand Down Expand Up @@ -330,7 +329,6 @@ xpkgkit_check_name_owner_cb(DBusPendingCall *pc, void *aptr)

EXIT:
if( rsp ) dbus_message_unref(rsp);
if( pc ) dbus_pending_call_unref(pc);
dbus_error_free(&err);
}

Expand Down
1 change: 0 additions & 1 deletion tklock.c
Expand Up @@ -3590,7 +3590,6 @@ static void tklock_ui_get_device_lock_cb(DBusPendingCall *pc, void *aptr)

EXIT:
if( rsp ) dbus_message_unref(rsp);
dbus_pending_call_unref(pc);
dbus_error_free(&err);
}

Expand Down

0 comments on commit 7ea70a0

Please sign in to comment.