mirror of https://github.com/labapart/gattlib
Introduce 'gattlib_characteristic_free_value()' to release memory allocated after reading GATT characteristic
parent
3ac5707c95
commit
0369342fd4
|
@ -439,3 +439,7 @@ int gattlib_write_without_response_char_by_handle(gatt_connection_t* connection,
|
|||
g_object_unref(dbus_characteristic.gatt);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void gattlib_characteristic_free_value(void *ptr) {
|
||||
free(ptr);
|
||||
}
|
||||
|
|
|
@ -266,7 +266,7 @@ static gboolean characteristics_read(gpointer user_data)
|
|||
}
|
||||
g_print("\n");
|
||||
|
||||
free(buffer);
|
||||
gattlib_characteristic_free_value(buffer);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,7 +107,7 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
printf("\n");
|
||||
|
||||
free(buffer);
|
||||
gattlib_characteristic_free_value(buffer);
|
||||
} else {
|
||||
ret = gattlib_write_char_by_uuid(connection, &g_uuid, &value_data, sizeof(value_data));
|
||||
if (ret != GATTLIB_SUCCESS) {
|
||||
|
|
|
@ -83,7 +83,7 @@ void *connect_ble(void *arg) {
|
|||
}
|
||||
printf("\n");
|
||||
|
||||
free(buffer);
|
||||
gattlib_characteristic_free_value(buffer);
|
||||
}
|
||||
} else {
|
||||
ret = gattlib_write_char_by_uuid(connection, &m_uuid, ¶ms->value_data, sizeof(params->value_data));
|
||||
|
|
|
@ -116,6 +116,10 @@ gattlib_discover_char.argtypes = [c_void_p, POINTER(POINTER(GattlibCharacteristi
|
|||
gattlib_read_char_by_uuid = gattlib.gattlib_read_char_by_uuid
|
||||
gattlib_read_char_by_uuid.argtypes = [c_void_p, POINTER(GattlibUuid), POINTER(c_void_p), POINTER(c_size_t)]
|
||||
|
||||
# void gattlib_characteristic_free_value(void* buffer);
|
||||
gattlib_characteristic_free_value = gattlib.gattlib_characteristic_free_value
|
||||
gattlib_characteristic_free_value.argtypes = [c_void_p]
|
||||
|
||||
# int gattlib_write_char_by_uuid(gatt_connection_t* connection, uuid_t* uuid, const void* buffer, size_t buffer_len)
|
||||
gattlib_write_char_by_uuid = gattlib.gattlib_write_char_by_uuid
|
||||
gattlib_write_char_by_uuid.argtypes = [c_void_p, POINTER(GattlibUuid), c_void_p, c_size_t]
|
||||
|
|
|
@ -87,6 +87,7 @@ class GattCharacteristic():
|
|||
for i in range(_buffer_len.value):
|
||||
value[i] = c_bytearray.contents[i]
|
||||
|
||||
gattlib_characteristic_free_value(_buffer)
|
||||
return value
|
||||
|
||||
def write(self, data, without_response=False):
|
||||
|
|
|
@ -464,6 +464,13 @@ int gattlib_read_char_by_uuid(gatt_connection_t* connection, uuid_t* uuid, void*
|
|||
*/
|
||||
int gattlib_read_char_by_uuid_async(gatt_connection_t* connection, uuid_t* uuid, gatt_read_cb_t gatt_read_cb);
|
||||
|
||||
/**
|
||||
* @brief Free buffer allocated by the characteristic reading to store the value
|
||||
*
|
||||
* @param buffer Buffer to free
|
||||
*/
|
||||
void gattlib_characteristic_free_value(void *ptr);
|
||||
|
||||
/**
|
||||
* @brief Function to write to the GATT characteristic UUID
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue