diff options
author | Tzafrir Poupko <[email protected]> | 2017-08-06 11:50:15 +0300 |
---|---|---|
committer | petreeftime <[email protected]> | 2017-08-06 15:19:46 +0300 |
commit | b3c053cd2707ae12de7d85fd994cdbda604503a6 (patch) | |
tree | 1f65a9b40c9c224abfe10eda72d135f8a263f0f5 /src | |
parent | 6a643b32c0b6ed538b557bf86ad4ba151dd966ff (diff) |
Fix memory leak with g_objects
BluetoothObject constructor maintains internally a g_object reference
to the underlying object.
This means that any g_object obtained externally should be unreferenced
after the BluetoothObject is constructed.
Signed-off-by: Tzafrir Poupko <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/BluetoothAdapter.cpp | 1 | ||||
-rw-r--r-- | src/BluetoothDevice.cpp | 5 | ||||
-rw-r--r-- | src/BluetoothGattCharacteristic.cpp | 5 | ||||
-rw-r--r-- | src/BluetoothGattDescriptor.cpp | 5 | ||||
-rw-r--r-- | src/BluetoothGattService.cpp | 5 | ||||
-rw-r--r-- | src/BluetoothManager.cpp | 1 |
6 files changed, 18 insertions, 4 deletions
diff --git a/src/BluetoothAdapter.cpp b/src/BluetoothAdapter.cpp index b28fabca..35c8865c 100644 --- a/src/BluetoothAdapter.cpp +++ b/src/BluetoothAdapter.cpp @@ -139,6 +139,7 @@ std::unique_ptr<BluetoothAdapter> BluetoothAdapter::make(Object *object, (adapter = object_get_adapter1(object)) != NULL) { std::unique_ptr<BluetoothAdapter> p(new BluetoothAdapter(adapter)); + g_object_unref(adapter); if ((name == nullptr || *name == p->get_name()) && (identifier == nullptr || *identifier == p->get_address()) && diff --git a/src/BluetoothDevice.cpp b/src/BluetoothDevice.cpp index b1ac0114..0a115876 100644 --- a/src/BluetoothDevice.cpp +++ b/src/BluetoothDevice.cpp @@ -194,6 +194,7 @@ std::unique_ptr<BluetoothDevice> BluetoothDevice::make(Object *object, (device = object_get_device1(object)) != NULL) { std::unique_ptr<BluetoothDevice> p(new BluetoothDevice(device)); + g_object_unref(device); if ((name == nullptr || *name == p->get_name()) && (identifier == nullptr || *identifier == p->get_address()) && @@ -496,7 +497,9 @@ BluetoothAdapter BluetoothDevice::get_adapter () throw BluetoothException(error_msg); } - return BluetoothAdapter(adapter); + auto res = BluetoothAdapter(adapter); + g_object_unref(adapter); + return res; } std::map<uint16_t, std::vector<uint8_t>> BluetoothDevice::get_manufacturer_data() diff --git a/src/BluetoothGattCharacteristic.cpp b/src/BluetoothGattCharacteristic.cpp index f38110cc..5104ee4d 100644 --- a/src/BluetoothGattCharacteristic.cpp +++ b/src/BluetoothGattCharacteristic.cpp @@ -109,6 +109,7 @@ std::unique_ptr<BluetoothGattCharacteristic> BluetoothGattCharacteristic::make( std::unique_ptr<BluetoothGattCharacteristic> p( new BluetoothGattCharacteristic(characteristic)); + g_object_unref(characteristic); if ((name == nullptr) && (identifier == nullptr || *identifier == p->get_uuid()) && @@ -260,7 +261,9 @@ BluetoothGattService BluetoothGattCharacteristic::get_service () throw BluetoothException(error_msg); } - return BluetoothGattService(service); + auto res = BluetoothGattService(service); + g_object_unref(service); + return res; } std::vector<unsigned char> BluetoothGattCharacteristic::get_value () diff --git a/src/BluetoothGattDescriptor.cpp b/src/BluetoothGattDescriptor.cpp index 9095c87b..12f3ac74 100644 --- a/src/BluetoothGattDescriptor.cpp +++ b/src/BluetoothGattDescriptor.cpp @@ -106,6 +106,7 @@ std::unique_ptr<BluetoothGattDescriptor> BluetoothGattDescriptor::make( std::unique_ptr<BluetoothGattDescriptor> p( new BluetoothGattDescriptor(descriptor)); + g_object_unref(descriptor); if ((name == nullptr) && (identifier == nullptr || *identifier == p->get_uuid()) && @@ -231,7 +232,9 @@ BluetoothGattCharacteristic BluetoothGattDescriptor::get_characteristic () throw BluetoothException(error_msg); } - return BluetoothGattCharacteristic(characteristic); + auto res = BluetoothGattCharacteristic(characteristic); + g_object_unref(characteristic); + return res; } std::vector<unsigned char> BluetoothGattDescriptor::get_value () diff --git a/src/BluetoothGattService.cpp b/src/BluetoothGattService.cpp index ac202dc7..f2099efa 100644 --- a/src/BluetoothGattService.cpp +++ b/src/BluetoothGattService.cpp @@ -77,6 +77,7 @@ std::unique_ptr<BluetoothGattService> BluetoothGattService::make( std::unique_ptr<BluetoothGattService> p( new BluetoothGattService(service)); + g_object_unref(service); if ((name == nullptr) && (identifier == nullptr || *identifier == p->get_uuid()) && @@ -117,7 +118,9 @@ BluetoothDevice BluetoothGattService::get_device () throw BluetoothException(error_msg); } - return BluetoothDevice(device); + auto res = BluetoothDevice(device); + g_object_unref(device); + return res; } bool BluetoothGattService::get_primary () diff --git a/src/BluetoothManager.cpp b/src/BluetoothManager.cpp index f83fb2e2..b4cdbd08 100644 --- a/src/BluetoothManager.cpp +++ b/src/BluetoothManager.cpp @@ -287,6 +287,7 @@ BluetoothManager::BluetoothManager() : event_list() Adapter1 *adapter = object_get_adapter1(object); if (adapter != NULL) { default_adapter = std::unique_ptr<BluetoothAdapter>(new BluetoothAdapter(adapter)); + g_object_unref(adapter); break; } } |