2012-09-14 16:10:08

by Syam Sidhardhan

[permalink] [raw]
Subject: [PATCH BlueZ v0 1/4] device: Remove dead code from get_properties()

---
src/device.c | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/src/device.c b/src/device.c
index 49021e4..77215f1 100644
--- a/src/device.c
+++ b/src/device.c
@@ -318,7 +318,7 @@ static DBusMessage *get_properties(DBusConnection *conn,
DBusMessageIter iter;
DBusMessageIter dict;
bdaddr_t src;
- char name[MAX_NAME_LENGTH + 1], srcaddr[18], dstaddr[18];
+ char name[MAX_NAME_LENGTH + 1], dstaddr[18];
char **str;
const char *ptr, *icon = NULL;
dbus_bool_t boolean;
@@ -348,7 +348,6 @@ static DBusMessage *get_properties(DBusConnection *conn,
ptr = NULL;
memset(name, 0, sizeof(name));
adapter_get_address(adapter, &src);
- ba2str(&src, srcaddr);

ptr = device->name;
dict_append_entry(&dict, "Name", DBUS_TYPE_STRING, &ptr);
--
1.7.4.1



2012-09-17 13:55:33

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH BlueZ v0 1/4] device: Remove dead code from get_properties()

Hi Syam,

On Fri, Sep 14, 2012 at 7:10 PM, Syam Sidhardhan <[email protected]> wrote:
> ---
> src/device.c | 3 +--
> 1 files changed, 1 insertions(+), 2 deletions(-)
>
> diff --git a/src/device.c b/src/device.c
> index 49021e4..77215f1 100644
> --- a/src/device.c
> +++ b/src/device.c
> @@ -318,7 +318,7 @@ static DBusMessage *get_properties(DBusConnection *conn,
> DBusMessageIter iter;
> DBusMessageIter dict;
> bdaddr_t src;
> - char name[MAX_NAME_LENGTH + 1], srcaddr[18], dstaddr[18];
> + char name[MAX_NAME_LENGTH + 1], dstaddr[18];
> char **str;
> const char *ptr, *icon = NULL;
> dbus_bool_t boolean;
> @@ -348,7 +348,6 @@ static DBusMessage *get_properties(DBusConnection *conn,
> ptr = NULL;
> memset(name, 0, sizeof(name));
> adapter_get_address(adapter, &src);
> - ba2str(&src, srcaddr);
>
> ptr = device->name;
> dict_append_entry(&dict, "Name", DBUS_TYPE_STRING, &ptr);
> --
> 1.7.4.1

All 4 patches were pushed, I just did some small changes to 3/4 to
avoid double checking dbus_connection_send_with_reply_and_block return
since in case of error it is guaranteed that the reply is NULL and the
error is set: http://dbus.freedesktop.org/doc/api/html/group__DBusConnection.html#ga8d6431f17a9e53c9446d87c2ba8409f0

So the code now just check the if the error is set.

--
Luiz Augusto von Dentz

2012-09-17 11:44:36

by Bastien Nocera

[permalink] [raw]
Subject: Re: [PATCH BlueZ v0 4/4] cups: Free D-Bus error

Em Fri, 2012-09-14 às 21:40 +0530, Syam Sidhardhan escreveu:
> If D-Bus error is set we should free it.

Looks good to me.

> ---
> profiles/cups/main.c | 9 +++++++--
> 1 files changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/profiles/cups/main.c b/profiles/cups/main.c
> index a884c6e..5aa927f 100644
> --- a/profiles/cups/main.c
> +++ b/profiles/cups/main.c
> @@ -446,8 +446,10 @@ static gboolean list_known_printers(const char *adapter)
>
> dbus_message_unref(message);
>
> - if (dbus_error_is_set(&error))
> + if (dbus_error_is_set(&error)) {
> + dbus_error_free(&error);
> return FALSE;
> + }
>
> dbus_message_iter_init(reply, &reply_iter);
> if (dbus_message_iter_get_arg_type(&reply_iter) != DBUS_TYPE_ARRAY) {
> @@ -549,8 +551,10 @@ static gboolean list_printers(void)
>
> dbus_error_init(&error);
> hcid_exists = dbus_bus_name_has_owner(conn, "org.bluez", &error);
> - if (dbus_error_is_set(&error))
> + if (dbus_error_is_set(&error)) {
> + dbus_error_free(&error);
> return TRUE;
> + }
>
> if (!hcid_exists)
> return TRUE;
> @@ -570,6 +574,7 @@ static gboolean list_printers(void)
> dbus_message_unref(message);
>
> if (dbus_error_is_set(&error)) {
> + dbus_error_free(&error);
> dbus_connection_unref(conn);
> /* No adapter */
> return TRUE;



2012-09-14 16:10:11

by Syam Sidhardhan

[permalink] [raw]
Subject: [PATCH BlueZ v0 4/4] cups: Free D-Bus error

If D-Bus error is set we should free it.
---
profiles/cups/main.c | 9 +++++++--
1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/profiles/cups/main.c b/profiles/cups/main.c
index a884c6e..5aa927f 100644
--- a/profiles/cups/main.c
+++ b/profiles/cups/main.c
@@ -446,8 +446,10 @@ static gboolean list_known_printers(const char *adapter)

dbus_message_unref(message);

- if (dbus_error_is_set(&error))
+ if (dbus_error_is_set(&error)) {
+ dbus_error_free(&error);
return FALSE;
+ }

dbus_message_iter_init(reply, &reply_iter);
if (dbus_message_iter_get_arg_type(&reply_iter) != DBUS_TYPE_ARRAY) {
@@ -549,8 +551,10 @@ static gboolean list_printers(void)

dbus_error_init(&error);
hcid_exists = dbus_bus_name_has_owner(conn, "org.bluez", &error);
- if (dbus_error_is_set(&error))
+ if (dbus_error_is_set(&error)) {
+ dbus_error_free(&error);
return TRUE;
+ }

if (!hcid_exists)
return TRUE;
@@ -570,6 +574,7 @@ static gboolean list_printers(void)
dbus_message_unref(message);

if (dbus_error_is_set(&error)) {
+ dbus_error_free(&error);
dbus_connection_unref(conn);
/* No adapter */
return TRUE;
--
1.7.4.1


2012-09-14 16:10:10

by Syam Sidhardhan

[permalink] [raw]
Subject: [PATCH BlueZ v0 3/4] gstavdtpsink: Free the D-Bus error on reply failure

If D-Bus error is set we should free it.
---
I'm not sure whether we can split the error message or not.

audio/gstavdtpsink.c | 18 +++++++++++++-----
1 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/audio/gstavdtpsink.c b/audio/gstavdtpsink.c
index ffaed7f..3427043 100644
--- a/audio/gstavdtpsink.c
+++ b/audio/gstavdtpsink.c
@@ -786,13 +786,22 @@ static gboolean gst_avdtp_sink_transport_get_properties(GstAvdtpSink *self)
msg = dbus_message_new_method_call("org.bluez", self->transport,
"org.bluez.MediaTransport",
"GetProperties");
+ if (!msg) {
+ GST_ERROR_OBJECT(self, "D-Bus Memory allocation failed");
+ return FALSE;
+ }
+
reply = dbus_connection_send_with_reply_and_block(self->data->conn,
msg, -1, &err);
+ dbus_message_unref(msg);

- if (dbus_error_is_set(&err) || reply == NULL) {
- GST_ERROR_OBJECT(self, "Failed to get transport properties: %s",
- err.message);
- goto fail;
+ if (!reply) {
+ if (dbus_error_is_set(&err)) {
+ GST_ERROR_OBJECT(self, "Failed to get transport "
+ "properties: %s", err.message);
+ dbus_error_free(&err);
+ }
+ return FALSE;
}

if (!dbus_message_iter_init(reply, &arg_i)) {
@@ -824,7 +833,6 @@ static gboolean gst_avdtp_sink_transport_get_properties(GstAvdtpSink *self)
return gst_avdtp_sink_update_caps(self);

fail:
- dbus_message_unref(msg);
dbus_message_unref(reply);
return FALSE;

--
1.7.4.1


2012-09-14 16:10:09

by Syam Sidhardhan

[permalink] [raw]
Subject: [PATCH BlueZ v0 2/4] adapter: Remove dead code from adapter_emit_device_found()

---
src/adapter.c | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 1c13b2d..facfa23 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2725,7 +2725,7 @@ void adapter_emit_device_found(struct btd_adapter *adapter,
struct remote_dev_info *dev)
{
struct btd_device *device;
- char peer_addr[18], local_addr[18];
+ char peer_addr[18];
const char *icon, *paddr = peer_addr;
dbus_bool_t paired = FALSE, trusted = FALSE;
dbus_int16_t rssi = dev->rssi;
@@ -2733,7 +2733,6 @@ void adapter_emit_device_found(struct btd_adapter *adapter,
size_t uuid_count;

ba2str(&dev->bdaddr, peer_addr);
- ba2str(&adapter->bdaddr, local_addr);

device = adapter_find_device(adapter, paddr);
if (device) {
--
1.7.4.1