Diff between b0780fdec31b5a0c37d0262a522f06fb9dc704bc and 39a3e9c173f9d04e0e5d8513ddf8479744b09eb3

Changed Files

File Additions Deletions Status
android/gatt.c +25 -14 modified

Full Patch

diff --git a/android/gatt.c b/android/gatt.c
index 004063c..5373397 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -2236,6 +2236,27 @@ static void read_desc_cb(guint8 status, const guint8 *pdu, guint16 len,
 	free(cb_data);
 }
 
+static struct desc_data *create_desc_data(int32_t conn_id,
+						const struct element_id *s_id,
+						const struct element_id *ch_id,
+						const struct element_id *d_id,
+						uint8_t primary)
+{
+	struct desc_data *d;
+
+	d = new0(struct desc_data, 1);
+	if (!d)
+		return NULL;
+
+	d->conn_id = conn_id;
+	d->srvc_id = s_id;
+	d->char_id = ch_id;
+	d->descr_id = d_id;
+	d->primary = primary;
+
+	return d;
+}
+
 static void handle_client_read_descriptor(const void *buf, uint16_t len)
 {
 	const struct hal_cmd_gatt_client_read_descriptor *cmd = buf;
@@ -2284,7 +2305,8 @@ static void handle_client_read_descriptor(const void *buf, uint16_t len)
 		goto failed;
 	}
 
-	cb_data = new0(struct desc_data, 1);
+	cb_data = create_desc_data(conn_id, &srvc->id, &ch->id, &descr->id,
+								primary);
 	if (!cb_data) {
 		error("gatt: Read descr. could not allocate callback data");
 
@@ -2292,12 +2314,6 @@ static void handle_client_read_descriptor(const void *buf, uint16_t len)
 		goto failed;
 	}
 
-	cb_data->conn_id = conn_id;
-	cb_data->srvc_id = &srvc->id;
-	cb_data->char_id = &ch->id;
-	cb_data->descr_id = &descr->id;
-	cb_data->primary = primary;
-
 	if (!gatt_read_char(dev->attrib, descr->handle, read_desc_cb,
 								cb_data)) {
 		free(cb_data);
@@ -2411,7 +2427,8 @@ static void handle_client_write_descriptor(const void *buf, uint16_t len)
 		goto failed;
 	}
 
-	cb_data = new0(struct desc_data, 1);
+	cb_data = create_desc_data(conn_id, &srvc->id, &ch->id, &descr->id,
+								primary);
 	if (!cb_data) {
 		error("gatt: Write descr. could not allocate callback data");
 
@@ -2419,12 +2436,6 @@ static void handle_client_write_descriptor(const void *buf, uint16_t len)
 		goto failed;
 	}
 
-	cb_data->conn_id = conn_id;
-	cb_data->srvc_id = &srvc->id;
-	cb_data->char_id = &ch->id;
-	cb_data->descr_id = &descr->id;
-	cb_data->primary = primary;
-
 	if (!gatt_write_char(dev->attrib, descr->handle, cmd->value, cmd->len,
 						write_descr_cb, cb_data)) {
 		free(cb_data);