Skip to content

Commit 13dc292

Browse files
committed
[Bugfix] Deinit mutex on buffer allocation failure
1 parent f53028b commit 13dc292

2 files changed

Lines changed: 19 additions & 18 deletions

File tree

src/NimBLEStream.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ struct NimBLEStream::ByteRingBuffer {
5858
m_buf = static_cast<uint8_t*>(malloc(capacity));
5959
if (!m_buf) {
6060
NIMBLE_LOGE(LOG_TAG, "Failed to allocate ring buffer memory");
61+
ble_npl_mutex_deinit(&m_mutex);
6162
return;
6263
}
6364
}

src/NimBLEStream.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class NimBLEStream : public Stream {
100100
*/
101101
void setRxOverflowCallback(RxOverflowCallback cb, void* userArg = nullptr) {
102102
m_rxOverflowCallback = cb;
103-
m_rxOverflowUserArg = userArg;
103+
m_rxOverflowUserArg = userArg;
104104
}
105105

106106
operator bool() const { return ready(); }
@@ -118,17 +118,17 @@ class NimBLEStream : public Stream {
118118
static void txDrainEventCb(struct ble_npl_event* ev);
119119
static void txDrainCalloutCb(struct ble_npl_event* ev);
120120

121-
ByteRingBuffer* m_txBuf{nullptr};
122-
ByteRingBuffer* m_rxBuf{nullptr};
123-
uint8_t m_txChunkBuf[MYNEWT_VAL(BLE_ATT_PREFERRED_MTU)];
124-
uint32_t m_txBufSize{1024};
125-
uint32_t m_rxBufSize{1024};
126-
ble_npl_event m_txDrainEvent{};
127-
ble_npl_callout m_txDrainCallout{};
121+
ByteRingBuffer* m_txBuf{nullptr};
122+
ByteRingBuffer* m_rxBuf{nullptr};
123+
uint8_t m_txChunkBuf[MYNEWT_VAL(BLE_ATT_PREFERRED_MTU)];
124+
uint32_t m_txBufSize{1024};
125+
uint32_t m_rxBufSize{1024};
126+
ble_npl_event m_txDrainEvent{};
127+
ble_npl_callout m_txDrainCallout{};
128128
RxOverflowCallback m_rxOverflowCallback{nullptr};
129-
void* m_rxOverflowUserArg{nullptr};
130-
bool m_coInitialized{false};
131-
bool m_eventInitialized{false};
129+
void* m_rxOverflowUserArg{nullptr};
130+
bool m_coInitialized{false};
131+
bool m_eventInitialized{false};
132132
};
133133

134134
# if MYNEWT_VAL(BLE_ROLE_PERIPHERAL)
@@ -203,13 +203,13 @@ class NimBLEStreamClient : public NimBLEStream {
203203

204204
// Attach a discovered remote characteristic; app owns discovery/connection.
205205
// Set subscribeNotify=true to receive notifications into RX buffer.
206-
bool begin(NimBLERemoteCharacteristic* pChr,
207-
bool subscribeNotify = false,
208-
uint32_t txBufSize = 1024,
209-
uint32_t rxBufSize = 1024);
210-
void end() override;
211-
void setNotifyCallback(NimBLERemoteCharacteristic::notify_callback cb) { m_userNotifyCallback = cb; }
212-
bool ready() const override;
206+
bool begin(NimBLERemoteCharacteristic* pChr,
207+
bool subscribeNotify = false,
208+
uint32_t txBufSize = 1024,
209+
uint32_t rxBufSize = 1024);
210+
void end() override;
211+
void setNotifyCallback(NimBLERemoteCharacteristic::notify_callback cb) { m_userNotifyCallback = cb; }
212+
bool ready() const override;
213213
virtual void flush() override;
214214

215215
using NimBLEStream::write; // Inherit template write overloads

0 commit comments

Comments
 (0)