Skip to content

Commit

Permalink
[dbus] Normalize DBusError initialization and cleanup
Browse files Browse the repository at this point in the history
There is some old code using dbus_error_init() calls from before
DBUS_ERROR_INIT macro was available.

Replace dbus_error_init() calls withDBUS_ERROR_INIT initializer macro and do
cleanup at logically the same level as the initialization was done.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed May 12, 2017
1 parent b7767d9 commit 6c21f18
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 37 deletions.
14 changes: 4 additions & 10 deletions modules/alarm.c
Expand Up @@ -126,9 +126,7 @@ static gboolean alarm_owner_monitor_dbus_cb(DBusMessage *const msg)
const gchar *service;
gssize retval;

DBusError error;
/* Register error channel */
dbus_error_init(&error);
DBusError error = DBUS_ERROR_INIT;

/* Extract result */
if (dbus_message_get_args(msg, &error,
Expand All @@ -140,7 +138,6 @@ static gboolean alarm_owner_monitor_dbus_cb(DBusMessage *const msg)
"Failed to get argument from %s.%s; %s",
"org.freedesktop.DBus", "NameOwnerChanged",
error.message);
dbus_error_free(&error);
goto EXIT;
}

Expand All @@ -159,8 +156,8 @@ static gboolean alarm_owner_monitor_dbus_cb(DBusMessage *const msg)
status = TRUE;

EXIT:
dbus_error_free(&error);
return status;

}

/**
Expand Down Expand Up @@ -252,12 +249,9 @@ static gboolean alarm_dialog_status_dbus_cb(DBusMessage *const msg)
alarm_ui_state_t alarm_ui_state = MCE_ALARM_UI_INVALID_INT32;
gboolean status = FALSE;
const gchar *sender = dbus_message_get_sender(msg);
DBusError error;
DBusError error = DBUS_ERROR_INIT;
dbus_int32_t dialog_status;

/* Register error channel */
dbus_error_init(&error);

mce_log(LL_DEVEL, "Received alarm dialog status signal from %s",
mce_dbus_get_name_owner_ident(sender));

Expand All @@ -270,7 +264,6 @@ static gboolean alarm_dialog_status_dbus_cb(DBusMessage *const msg)
VISUAL_REMINDERS_SIGNAL_IF,
VISUAL_REMINDER_STATUS_SIG,
error.message);
dbus_error_free(&error);
goto EXIT;
}

Expand Down Expand Up @@ -304,6 +297,7 @@ static gboolean alarm_dialog_status_dbus_cb(DBusMessage *const msg)
status = TRUE;

EXIT:
dbus_error_free(&error);
return status;
}

Expand Down
3 changes: 2 additions & 1 deletion modules/callstate.c
Expand Up @@ -1497,7 +1497,6 @@ change_call_state_dbus_cb(DBusMessage *const msg)
mce_log(LL_ERR, "Failed to get argument from %s.%s: %s",
MCE_REQUEST_IF, MCE_CALL_STATE_CHANGE_REQ,
error.message);
dbus_error_free(&error);
goto EXIT;
}

Expand Down Expand Up @@ -1556,6 +1555,8 @@ change_call_state_dbus_cb(DBusMessage *const msg)
if( reply )
dbus_message_unref(reply);

dbus_error_free(&error);

return status;
}

Expand Down
14 changes: 4 additions & 10 deletions modules/display.c
Expand Up @@ -8789,10 +8789,7 @@ static gboolean mdy_dbus_handle_cabc_mode_owner_lost_sig(DBusMessage *const msg)
const gchar *old_name;
const gchar *new_name;
const gchar *service;
DBusError error;

/* Register error channel */
dbus_error_init(&error);
DBusError error = DBUS_ERROR_INIT;

/* Extract result */
if (dbus_message_get_args(msg, &error,
Expand All @@ -8803,7 +8800,6 @@ static gboolean mdy_dbus_handle_cabc_mode_owner_lost_sig(DBusMessage *const msg)
mce_log(LL_ERR, "Failed to get argument from %s.%s; %s",
"org.freedesktop.DBus", "NameOwnerChanged",
error.message);
dbus_error_free(&error);
goto EXIT;
}

Expand All @@ -8814,6 +8810,7 @@ static gboolean mdy_dbus_handle_cabc_mode_owner_lost_sig(DBusMessage *const msg)
status = TRUE;

EXIT:
dbus_error_free(&error);
return status;
}

Expand Down Expand Up @@ -8854,10 +8851,7 @@ static gboolean mdy_dbus_handle_cabc_mode_set_req(DBusMessage *const msg)
const gchar *dbus_cabc_mode = NULL;
gboolean status = FALSE;
gint i;
DBusError error;

/* Register error channel */
dbus_error_init(&error);
DBusError error = DBUS_ERROR_INIT;

if (sender == NULL) {
mce_log(LL_ERR, "invalid set CABC mode request (NULL sender)");
Expand All @@ -8874,7 +8868,6 @@ static gboolean mdy_dbus_handle_cabc_mode_set_req(DBusMessage *const msg)
mce_log(LL_ERR, "Failed to get argument from %s.%s; %s",
MCE_REQUEST_IF, MCE_CABC_MODE_REQ,
error.message);
dbus_error_free(&error);
goto EXIT;
}

Expand Down Expand Up @@ -8922,6 +8915,7 @@ static gboolean mdy_dbus_handle_cabc_mode_set_req(DBusMessage *const msg)
}

EXIT:
dbus_error_free(&error);
return status;
}

Expand Down
14 changes: 4 additions & 10 deletions modules/led.c
Expand Up @@ -2028,10 +2028,7 @@ static gboolean led_activate_pattern_dbus_cb(DBusMessage *const msg)
dbus_bool_t no_reply = dbus_message_get_no_reply(msg);
const gchar *pattern = NULL;
gboolean status = FALSE;
DBusError error;

/* Register error channel */
dbus_error_init(&error);
DBusError error = DBUS_ERROR_INIT;

if (dbus_message_get_args(msg, &error,
DBUS_TYPE_STRING, &pattern,
Expand All @@ -2041,7 +2038,6 @@ static gboolean led_activate_pattern_dbus_cb(DBusMessage *const msg)
"Failed to get argument from %s.%s: %s",
MCE_REQUEST_IF, MCE_ACTIVATE_LED_PATTERN,
error.message);
dbus_error_free(&error);
goto EXIT;
}

Expand All @@ -2059,6 +2055,7 @@ static gboolean led_activate_pattern_dbus_cb(DBusMessage *const msg)
}

EXIT:
dbus_error_free(&error);
return status;
}

Expand All @@ -2073,10 +2070,7 @@ static gboolean led_deactivate_pattern_dbus_cb(DBusMessage *const msg)
dbus_bool_t no_reply = dbus_message_get_no_reply(msg);
const gchar *pattern = NULL;
gboolean status = FALSE;
DBusError error;

/* Register error channel */
dbus_error_init(&error);
DBusError error = DBUS_ERROR_INIT;

if (dbus_message_get_args(msg, &error,
DBUS_TYPE_STRING, &pattern,
Expand All @@ -2086,7 +2080,6 @@ static gboolean led_deactivate_pattern_dbus_cb(DBusMessage *const msg)
"Failed to get argument from %s.%s: %s",
MCE_REQUEST_IF, MCE_DEACTIVATE_LED_PATTERN,
error.message);
dbus_error_free(&error);
goto EXIT;
}

Expand All @@ -2104,6 +2097,7 @@ static gboolean led_deactivate_pattern_dbus_cb(DBusMessage *const msg)
}

EXIT:
dbus_error_free(&error);
return status;
}

Expand Down
2 changes: 1 addition & 1 deletion modules/radiostates.c
Expand Up @@ -396,7 +396,6 @@ static gboolean req_radio_states_change_dbus_cb(DBusMessage *const msg)
"Failed to get argument from %s.%s: %s",
MCE_REQUEST_IF, MCE_RADIO_STATES_CHANGE_REQ,
error.message);
dbus_error_free(&error);
goto EXIT;
}

Expand All @@ -411,6 +410,7 @@ static gboolean req_radio_states_change_dbus_cb(DBusMessage *const msg)
}

EXIT:
dbus_error_free(&error);
return status;
}

Expand Down
7 changes: 2 additions & 5 deletions tests/ut/ut_display.c
Expand Up @@ -679,12 +679,9 @@ static DBusConnection *stub__dbus_connection = NULL;
EXTERN_STUB (
DBusConnection *, dbus_connection_get, (void))
{
DBusBusType bus_type = DBUS_BUS_SYSTEM;
DBusError error;

dbus_error_init(&error);

if( !stub__dbus_connection ) {
DBusBusType bus_type = DBUS_BUS_SYSTEM;
DBusError error = DBUS_ERROR_INIT;
if( (stub__dbus_connection = dbus_bus_get(bus_type,
&error)) == NULL ) {
printf("%s: Failed to open connection to message bus; %s",
Expand Down
1 change: 1 addition & 0 deletions tools/mcetool.c
Expand Up @@ -105,6 +105,7 @@ static DBusConnection *xdbus_init(void)
err.name, err.message);
}
errorf("MCE not running, terminating\n");
dbus_error_free(&err);
exit(EXIT_FAILURE);
}

Expand Down

0 comments on commit 6c21f18

Please sign in to comment.