Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove unnecessary unrefs to dbus message #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/modules/systemd/dbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,13 @@ DBusMessage *dbus_exchange_message(DBusMessage *msg) {
msg = dbus_pending_call_steal_reply(pending);
if (NULL == msg) {
zabbix_log(LOG_LEVEL_ERR, LOG_PREFIX "returned message is null");
dbus_message_unref(msg);
return NULL;
}
dbus_pending_call_unref(pending);

// check for errors
if (dbus_check_error(msg)){
dbus_message_unref(msg);
if (dbus_check_error(msg))
return NULL;
}

return msg;
}
Expand Down
6 changes: 0 additions & 6 deletions src/modules/systemd/libzbxsystemd.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ static int SYSTEMD_UNIT_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)

if (NULL == (msg = dbus_exchange_message(msg))) {
SET_MSG_RESULT(result, strdup("failed to list units"));
dbus_message_unref(msg);
return res;
}

Expand All @@ -191,7 +190,6 @@ static int SYSTEMD_UNIT_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)

if (DBUS_TYPE_ARRAY != dbus_message_iter_get_arg_type(&args)) {
zabbix_log(LOG_LEVEL_ERR, LOG_PREFIX "returned value is not an array");
dbus_message_unref(msg);
return res;
}

Expand Down Expand Up @@ -423,20 +421,17 @@ static int SYSTEMD_SERVICE_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *resul

if (NULL == (msg = dbus_exchange_message(msg))) {
SET_MSG_RESULT(result, strdup("failed to list units"));
dbus_message_unref(msg);
return res;
}

// check result message
if (!dbus_message_iter_init(msg, &args)) {
zabbix_log(LOG_LEVEL_ERR, LOG_PREFIX "no value returned");
dbus_message_unref(msg);
return res;
}

if (DBUS_TYPE_ARRAY != dbus_message_iter_get_arg_type(&args)) {
zabbix_log(LOG_LEVEL_ERR, LOG_PREFIX "returned value is not an array");
dbus_message_unref(msg);
return res;
}

Expand All @@ -452,7 +447,6 @@ static int SYSTEMD_SERVICE_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *resul
dbus_message_iter_next_n(&unit, 6);
if (DBUS_TYPE_INVALID == (type = dbus_message_iter_get_arg_type(&unit))) {
zabbix_log(LOG_LEVEL_ERR, LOG_PREFIX "unexpected value type");
dbus_message_unref(msg);
goto next_unit;
}

Expand Down
4 changes: 0 additions & 4 deletions src/modules/systemd/systemd.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,21 @@ int systemd_get_unit(char *s, size_t n, const char* unit)

dbus_message_iter_init_append(msg, &args);
if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &c)){
dbus_message_unref(msg);
return FAIL;
}

if (NULL == (msg = dbus_exchange_message(msg))){
dbus_message_unref(msg);
return FAIL;
}

// read value
if (!dbus_message_iter_init(msg, &args)) {
zabbix_log(LOG_LEVEL_ERR, LOG_PREFIX "message has no arguments");
dbus_message_unref(msg);
return FAIL;
}

if (DBUS_TYPE_OBJECT_PATH != (type = dbus_message_iter_get_arg_type(&args))) {
zabbix_log(LOG_LEVEL_ERR, LOG_PREFIX "argument is not an object path: %c", type);
dbus_message_unref(msg);
return FAIL;
}

Expand Down