summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2006-08-23 15:05:23 +0000
committerJohan Hedberg <johan.hedberg@nokia.com>2006-08-23 15:05:23 +0000
commit1aa9e2bb9fbbdeeed3b2d5086929d0ed3bb42993 (patch)
treeb4550d1328222f41ee0206bb18a9468de37f6556
parent684ba3688de17a3b8a6defd3139e1b8bf8971ef5 (diff)
Fix memory leak and coding style in rfcomm patch
-rw-r--r--hcid/dbus-rfcomm.c63
-rw-r--r--hcid/dbus-sdp.c14
2 files changed, 38 insertions, 39 deletions
diff --git a/hcid/dbus-rfcomm.c b/hcid/dbus-rfcomm.c
index 61a0365f..fdc4a21f 100644
--- a/hcid/dbus-rfcomm.c
+++ b/hcid/dbus-rfcomm.c
@@ -456,25 +456,25 @@ static struct rfcomm_node *rfcomm_bind(bdaddr_t *src, const char *bda, uint8_t c
return node;
}
-static sdp_record_t *get_record_from_string (const char *dst,
+static sdp_record_t *get_record_from_string(const char *dst,
const char *string)
{
uuid_t short_uuid;
- uuid_t *uuid;
+ uuid_t *uuid = NULL;
sdp_record_t *rec = NULL;
unsigned int data0, data4;
unsigned short data1, data2, data3, data5;
long handle;
/* Check if the string is a service name */
- short_uuid.value.uuid16 = sdp_str2svclass (string);
+ short_uuid.value.uuid16 = sdp_str2svclass(string);
if (short_uuid.value.uuid16) {
short_uuid.type = SDP_UUID16;
- uuid = sdp_uuid_to_uuid128 (&short_uuid);
- rec = find_record_by_uuid (dst, uuid);
- } else if (sscanf (string, "%8x-%4hx-%4hx-%4hx-%8x%4hx", &data0,
- &data1, &data2, &data3, &data4, &data5) == 6) {
+ uuid = sdp_uuid_to_uuid128(&short_uuid);
+ rec = find_record_by_uuid(dst, uuid);
+ } else if (sscanf(string, "%8x-%4hx-%4hx-%4hx-%8x%4hx", &data0,
+ &data1, &data2, &data3, &data4, &data5) == 6) {
data0 = htonl(data0);
data1 = htons(data1);
data2 = htons(data2);
@@ -482,19 +482,22 @@ static sdp_record_t *get_record_from_string (const char *dst,
data4 = htonl(data4);
data5 = htons(data5);
- uuid = malloc (sizeof(uuid_t));
+ uuid = bt_malloc(sizeof(uuid_t));
uuid->type = SDP_UUID128;
- memcpy (&uuid->value.uuid128.data[0], &data0, 4);
- memcpy (&uuid->value.uuid128.data[4], &data1, 2);
- memcpy (&uuid->value.uuid128.data[6], &data2, 2);
- memcpy (&uuid->value.uuid128.data[8], &data3, 2);
- memcpy (&uuid->value.uuid128.data[10], &data4, 4);
- memcpy (&uuid->value.uuid128.data[14], &data5, 2);
- rec = find_record_by_uuid (dst, uuid);
- } else if ((handle = strtol (string, (char **)NULL, 0))) {
- rec = find_record_by_handle (dst, handle);
- }
+ memcpy(&uuid->value.uuid128.data[0], &data0, 4);
+ memcpy(&uuid->value.uuid128.data[4], &data1, 2);
+ memcpy(&uuid->value.uuid128.data[6], &data2, 2);
+ memcpy(&uuid->value.uuid128.data[8], &data3, 2);
+ memcpy(&uuid->value.uuid128.data[10], &data4, 4);
+ memcpy(&uuid->value.uuid128.data[14], &data5, 2);
+
+ rec = find_record_by_uuid(dst, uuid);
+ } else if ((handle = strtol(string, NULL, 0)))
+ rec = find_record_by_handle(dst, handle);
+
+ if (uuid)
+ bt_free(uuid);
return rec;
}
@@ -519,16 +522,16 @@ static DBusHandlerResult rfcomm_connect_req(DBusConnection *conn,
hci_devba(dbus_data->dev_id, &bdaddr);
- rec = get_record_from_string (dst, string);
+ rec = get_record_from_string(dst, string);
if (!rec)
- return error_record_does_not_exist (conn, msg);
+ return error_record_does_not_exist(conn, msg);
if (sdp_get_access_protos(rec, &protos) == 0)
- ch = sdp_get_proto_port (protos, RFCOMM_UUID);
+ ch = sdp_get_proto_port(protos, RFCOMM_UUID);
if (ch == -1)
- return error_record_does_not_exist (conn, msg);
+ return error_record_does_not_exist(conn, msg);
if (find_pending_connect(dst, ch))
return error_connect_in_progress(conn, msg);
@@ -553,25 +556,25 @@ static DBusHandlerResult rfcomm_cancel_connect_req(DBusConnection *conn,
struct pending_connect *pending;
if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_STRING, &dst,
- DBUS_TYPE_STRING, &string,
- DBUS_TYPE_INVALID))
+ DBUS_TYPE_STRING, &dst,
+ DBUS_TYPE_STRING, &string,
+ DBUS_TYPE_INVALID))
return error_invalid_arguments(conn, msg);
hci_devba(dbus_data->dev_id, &bdaddr);
- rec = get_record_from_string (dst, string);
+ rec = get_record_from_string(dst, string);
if (!rec)
- return error_record_does_not_exist (conn, msg);
+ return error_record_does_not_exist(conn, msg);
if (sdp_get_access_protos(rec, &protos) == 0)
- ch = sdp_get_proto_port (protos, RFCOMM_UUID);
+ ch = sdp_get_proto_port(protos, RFCOMM_UUID);
if (ch == -1)
- return error_record_does_not_exist (conn, msg);
+ return error_record_does_not_exist(conn, msg);
- reply = dbus_message_new_method_return (msg);
+ reply = dbus_message_new_method_return(msg);
if (!reply)
return DBUS_HANDLER_RESULT_NEED_MEMORY;
diff --git a/hcid/dbus-sdp.c b/hcid/dbus-sdp.c
index 2634a5ea..2a448af4 100644
--- a/hcid/dbus-sdp.c
+++ b/hcid/dbus-sdp.c
@@ -835,8 +835,8 @@ search_request:
static int sdp_uuid_comp_func(const void *key1, const void *key2)
{
- const uuid_t *a = (const uuid_t *)key1;
- const uuid_t *b = (const uuid_t *)key2;
+ const uuid_t *a = key1;
+ const uuid_t *b = key2;
if (a->type != b->type)
return 1;
@@ -844,14 +844,11 @@ static int sdp_uuid_comp_func(const void *key1, const void *key2)
switch (a->type) {
case SDP_UUID16:
return !(a->value.uuid16 == b->value.uuid16);
- break;
case SDP_UUID32:
return !(a->value.uuid32 == b->value.uuid32);
- break;
case SDP_UUID128:
return !memcmp(&a->value.uuid128, &b->value.uuid128,
sizeof(uint128_t));
- break;
}
return 1;
}
@@ -861,8 +858,7 @@ sdp_record_t *find_record_by_uuid(const char *address, uuid_t *uuid)
struct slist *lp, *lr;
struct service_provider *p;
struct service_record *r;
- sdp_list_t *list = 0;
-
+ sdp_list_t *list = NULL;
for (lp = sdp_cache; lp; lp = lp->next) {
p = lp->data;
@@ -872,10 +868,10 @@ sdp_record_t *find_record_by_uuid(const char *address, uuid_t *uuid)
for (lr = p->lrec; lr; lr = lr->next) {
r = lr->data;
/* Check whether the record has the correct uuid */
- if (sdp_get_service_classes(r->record, &list) !=0)
+ if (sdp_get_service_classes(r->record, &list) != 0)
continue;
- if (sdp_list_find (list, &uuid, sdp_uuid_comp_func))
+ if (sdp_list_find(list, &uuid, sdp_uuid_comp_func))
return r->record;
}
}