[PATCH v2 2/2] Use attribute data list memory allocation function on attrib server

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 src/attrib-server.c |   18 +++---------------
 1 files changed, 3 insertions(+), 15 deletions(-)

diff --git a/src/attrib-server.c b/src/attrib-server.c
index 62c10f4..2bfeed4 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
@@ -381,17 +381,13 @@ static uint16_t read_by_group(struct gatt_channel *channel, uint16_t start,
 
 	length = g_slist_length(groups);
 
-	adl = g_new0(struct att_data_list, 1);
-	adl->len = last_size + 4;	/* Length of each element */
-	adl->num = length;	/* Number of primary or secondary services */
-	adl->data = g_malloc(length * sizeof(uint8_t *));
+	adl = att_data_list_alloc(length, last_size + 4);
 
 	for (i = 0, l = groups; l; l = l->next, i++) {
 		uint8_t *value;
 
 		cur = l->data;
 
-		adl->data[i] = g_malloc(adl->len);
 		value = (void *) adl->data[i];
 
 		att_put_u16(cur->handle, value);
@@ -472,16 +468,12 @@ static uint16_t read_by_type(struct gatt_channel *channel, uint16_t start,
 	/* Handle length plus attribute value length */
 	length += 2;
 
-	adl = g_new0(struct att_data_list, 1);
-	adl->len = length;	/* Length of each element */
-	adl->num = num;		/* Number of primary or secondary services */
-	adl->data = g_malloc(num * sizeof(uint8_t *));
+	adl = att_data_list_alloc(num, length);
 
 	for (i = 0, l = types; l; i++, l = l->next) {
 		uint8_t *value;
 
 		a = l->data;
-		adl->data[i] = g_malloc(length);
 
 		value = (void *) adl->data[i];
 
@@ -545,16 +537,12 @@ static int find_info(uint16_t start, uint16_t end, uint8_t *pdu, int len)
 		format = 0x02;
 	}
 
-	adl = g_new0(struct att_data_list, 1);
-	adl->len = length + 2;	/* Length of each element */
-	adl->num = num;		/* Number of primary or secondary services */
-	adl->data = g_malloc(num * sizeof(uint8_t *));
+	adl = att_data_list_alloc(num, length + 2);
 
 	for (i = 0, l = info; l; i++, l = l->next) {
 		uint8_t *value;
 
 		a = l->data;
-		adl->data[i] = g_malloc(adl->len);
 
 		value = (void *) adl->data[i];
 
-- 
1.7.4.1

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux