Skip to content

Commit

Permalink
Merge pull request #121 from taks/fix-memory-leak
Browse files Browse the repository at this point in the history
Fix memory leak
  • Loading branch information
taks authored Apr 10, 2024
2 parents b6f8611 + 8d280f0 commit bab0fbb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#![allow(clippy::single_match)]
#![allow(static_mut_refs)]
#![feature(decl_macro)]
#![feature(get_mut_unchecked)]
#![doc = include_str!("../README.md")]
extern crate alloc;

Expand Down
6 changes: 3 additions & 3 deletions src/server/ble_characteristic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::cpfd::Cpfd;

use crate::{
utilities::{
as_mut_ptr, ble_npl_hw_enter_critical, ble_npl_hw_exit_critical, mutex::Mutex, os_mbuf_append,
ble_npl_hw_enter_critical, ble_npl_hw_exit_critical, mutex::Mutex, os_mbuf_append,
voidp_to_ref, BleUuid,
},
AttValue, BLEConnDesc, BLEDescriptor, BLEDevice, DescriptorProperties, OnWriteArgs, BLE2904,
Expand Down Expand Up @@ -206,8 +206,8 @@ impl BLECharacteristic {
}
self.svc_def_descriptors.clear();

for dsc in &self.descriptors {
let arg = unsafe { as_mut_ptr(Arc::into_raw(dsc.clone())) };
for dsc in &mut self.descriptors {
let arg = unsafe { Arc::get_mut_unchecked(dsc) } as *mut Mutex<BLEDescriptor>;
let dsc = dsc.lock();
self
.svc_def_descriptors
Expand Down
7 changes: 3 additions & 4 deletions src/server/ble_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use esp_idf_sys::ble_uuid_any_t;

use crate::{
ble,
utilities::{as_mut_ptr, mutex::Mutex, BleUuid},
utilities::{mutex::Mutex, BleUuid},
BLECharacteristic, BLEError,
};

Expand Down Expand Up @@ -43,10 +43,9 @@ impl BLEService {

if self.characteristics.is_empty() {
} else {
for chr in &self.characteristics {
let arg = unsafe { as_mut_ptr(Arc::into_raw(chr.clone())) };
for chr in &mut self.characteristics {
let arg = unsafe { Arc::get_mut_unchecked(chr) } as *mut Mutex<BLECharacteristic>;
let mut chr = chr.lock();

self
.svc_def_characteristics
.push(esp_idf_sys::ble_gatt_chr_def {
Expand Down

0 comments on commit bab0fbb

Please sign in to comment.