From: Mikel Astiz <mikel.astiz.oss@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Mikel Astiz <mikel.astiz@bmw-carit.de>
Subject: [PATCH obexd v0 2/2] client: Simplify error-handling code
Date: Fri, 18 May 2012 09:54:04 +0200 [thread overview]
Message-ID: <1337327644-17920-2-git-send-email-mikel.astiz.oss@gmail.com> (raw)
In-Reply-To: <1337327644-17920-1-git-send-email-mikel.astiz.oss@gmail.com>
From: Mikel Astiz <mikel.astiz@bmw-carit.de>
Refactor error-handling code to avoid duplicated code.
---
client/manager.c | 48 ++++++++++++++++++------------------------------
1 files changed, 18 insertions(+), 30 deletions(-)
diff --git a/client/manager.c b/client/manager.c
index 53f0d0f..b6d4afc 100644
--- a/client/manager.c
+++ b/client/manager.c
@@ -286,32 +286,26 @@ static void pull_obc_session_callback(struct obc_session *session,
DBusMessage *reply;
GError *gerr = NULL;
- if (err != NULL) {
- reply = g_dbus_create_error(data->message,
- "org.openobex.Error.Failed",
- "%s", err->message);
+ if (err != NULL)
goto fail;
- }
pull = obc_transfer_get("text/x-vcard", NULL, data->filename, &gerr);
- if (pull == NULL) {
- reply = g_dbus_create_error(data->message,
- "org.openobex.Error.Failed",
- "%s", gerr->message);
+ if (pull == NULL)
goto fail;
- }
if (!obc_session_queue(session, pull, pull_complete_callback, data,
- &gerr)) {
- reply = g_dbus_create_error(data->message,
- "org.openobex.Error.Failed",
- "%s", gerr->message);
+ &gerr))
goto fail;
- }
return;
fail:
+ if (err == NULL)
+ err = gerr;
+
+ reply = g_dbus_create_error(data->message,
+ "org.openobex.Error.Failed",
+ "%s", err->message);
g_dbus_send_message(data->connection, reply);
shutdown_session(session);
dbus_message_unref(data->message);
@@ -513,33 +507,27 @@ static void capability_obc_session_callback(struct obc_session *session,
DBusMessage *reply;
GError *gerr = NULL;
- if (err != NULL) {
- reply = g_dbus_create_error(data->message,
- "org.openobex.Error.Failed",
- "%s", err->message);
+ if (err != NULL)
goto fail;
- }
pull = obc_transfer_get("x-obex/capability", NULL, data->filename,
&gerr);
- if (pull == NULL) {
- reply = g_dbus_create_error(data->message,
- "org.openobex.Error.Failed",
- "%s", gerr->message);
+ if (pull == NULL)
goto fail;
- }
if (!obc_session_queue(session, pull, capabilities_complete_callback,
- data, &gerr)) {
- reply = g_dbus_create_error(data->message,
- "org.openobex.Error.Failed",
- "%s", gerr->message);
+ data, &gerr))
goto fail;
- }
return;
fail:
+ if (err == NULL)
+ err = gerr;
+
+ reply = g_dbus_create_error(data->message,
+ "org.openobex.Error.Failed",
+ "%s", err->message);
g_dbus_send_message(data->connection, reply);
shutdown_session(session);
dbus_message_unref(data->message);
--
1.7.7.6
next prev parent reply other threads:[~2012-05-18 7:54 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-18 7:54 [PATCH obexd v0 1/2] client: Fix NULL dereference in case of error Mikel Astiz
2012-05-18 7:54 ` Mikel Astiz [this message]
2012-05-18 19:25 ` Johan Hedberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1337327644-17920-2-git-send-email-mikel.astiz.oss@gmail.com \
--to=mikel.astiz.oss@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=mikel.astiz@bmw-carit.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).