diff options
author | Sven Gothel <[email protected]> | 2020-09-28 08:40:12 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-09-28 08:40:12 +0200 |
commit | 82051f22e374f9fb90a20685c7338cdf58e4c170 (patch) | |
tree | 30c0c34dd04a77fbe6c48b5f6e71fc5be4a4423e /src | |
parent | 99c51fa4b75f38bc5e021f9e87cd5cd4dcb94898 (diff) |
valgrind memcheck: AttPDUMsg::getSpecialized() return std::shared_ptr<const AttPDUMsg>, fix bug in GATTHandler::l2capReaderThreadImpl()
Diffstat (limited to 'src')
-rw-r--r-- | src/direct_bt/ATTPDUTypes.cpp | 4 | ||||
-rw-r--r-- | src/direct_bt/GATTHandler.cpp | 14 |
2 files changed, 6 insertions, 12 deletions
diff --git a/src/direct_bt/ATTPDUTypes.cpp b/src/direct_bt/ATTPDUTypes.cpp index 82c283dd..2bdcf5cf 100644 --- a/src/direct_bt/ATTPDUTypes.cpp +++ b/src/direct_bt/ATTPDUTypes.cpp @@ -114,7 +114,7 @@ std::string AttErrorRsp::getPlainErrorString(const ErrorCode errorCode) noexcept return "Error Reserved for future use"; } -AttPDUMsg* AttPDUMsg::getSpecialized(const uint8_t * buffer, int const buffer_size) noexcept { +std::shared_ptr<const AttPDUMsg> AttPDUMsg::getSpecialized(const uint8_t * buffer, int const buffer_size) noexcept { const uint8_t opc = *buffer; AttPDUMsg * res; switch( opc ) { @@ -152,5 +152,5 @@ AttPDUMsg* AttPDUMsg::getSpecialized(const uint8_t * buffer, int const buffer_si case ATT_SIGNED_WRITE_CMD: res = new AttPDUMsg(buffer, buffer_size); break; default: res = new AttPDUMsg(buffer, buffer_size); break; } - return res; + return std::shared_ptr<const AttPDUMsg>(res); } diff --git a/src/direct_bt/GATTHandler.cpp b/src/direct_bt/GATTHandler.cpp index d6251d4d..3414765d 100644 --- a/src/direct_bt/GATTHandler.cpp +++ b/src/direct_bt/GATTHandler.cpp @@ -206,11 +206,11 @@ void GATTHandler::l2capReaderThreadImpl() { len = l2cap.read(rbuffer.get_wptr(), rbuffer.getSize()); if( 0 < len ) { - const AttPDUMsg * attPDU = AttPDUMsg::getSpecialized(rbuffer.get_ptr(), len); + std::shared_ptr<const AttPDUMsg> attPDU = AttPDUMsg::getSpecialized(rbuffer.get_ptr(), len); const AttPDUMsg::Opcode opc = attPDU->getOpcode(); if( AttPDUMsg::Opcode::ATT_HANDLE_VALUE_NTF == opc ) { - const AttHandleValueRcv * a = static_cast<const AttHandleValueRcv*>(attPDU); + const AttHandleValueRcv * a = static_cast<const AttHandleValueRcv*>(attPDU.get()); COND_PRINT(env.DEBUG_DATA, "GATTHandler: NTF: %s, listener %zd", a->toString().c_str(), characteristicListenerList.size()); GATTCharacteristicRef decl = findCharacterisicsByValueHandle(a->getHandle()); const std::shared_ptr<TROOctets> data(new POctets(a->getValue())); @@ -228,9 +228,8 @@ void GATTHandler::l2capReaderThreadImpl() { } i++; }); - attPDU = nullptr; } else if( AttPDUMsg::Opcode::ATT_HANDLE_VALUE_IND == opc ) { - const AttHandleValueRcv * a = static_cast<const AttHandleValueRcv*>(attPDU); + const AttHandleValueRcv * a = static_cast<const AttHandleValueRcv*>(attPDU.get()); COND_PRINT(env.DEBUG_DATA, "GATTHandler: IND: %s, sendIndicationConfirmation %d, listener %zd", a->toString().c_str(), sendIndicationConfirmation, characteristicListenerList.size()); bool cfmSent = false; if( sendIndicationConfirmation ) { @@ -254,16 +253,11 @@ void GATTHandler::l2capReaderThreadImpl() { } i++; }); - attPDU = nullptr; } else if( AttPDUMsg::Opcode::ATT_MULTIPLE_HANDLE_VALUE_NTF == opc ) { // FIXME TODO .. ERR_PRINT("GATTHandler: MULTI-NTF not implemented: %s", attPDU->toString().c_str()); } else { - attPDURing.putBlocking( std::shared_ptr<const AttPDUMsg>( attPDU ) ); - attPDU = nullptr; - } - if( nullptr != attPDU ) { - delete attPDU; // free unhandled PDU + attPDURing.putBlocking( attPDU ); } } else if( ETIMEDOUT != errno && !l2capReaderShallStop ) { // expected exits IRQ_PRINT("GATTHandler::l2capReaderThread: l2cap read error -> Stop; l2cap.read %d", len); |