diff --git a/src/Sodaq_nbIOT.cpp b/src/Sodaq_nbIOT.cpp index adedeb5..41269a6 100644 --- a/src/Sodaq_nbIOT.cpp +++ b/src/Sodaq_nbIOT.cpp @@ -609,20 +609,26 @@ ResponseTypes Sodaq_nbIOT::_socketReceiveParser(ResponseTypes &response, const c // ,,,,, SerialUSB.println(__FILE__": _socketReceiveParser() buffer:"); SerialUSB.println(buffer); - // create a result buffer for the HEX string input + /** + * create a result buffer for the HEX string input + * 250 is SODAQ_AT_DEVICE_DEFAULT_INPUT_BUFFER_SIZE defined in Sodaq_AT_Device.h + * should probably refactor some more and move it to Sodaq_AT_Device.h + * we probably only need half of this (+1) + */ auto * resultBuffer = static_cast(malloc(250)); - memset(resultBuffer,0,250); + memset(resultBuffer, 0, 250); if (sscanf(buffer, "%d,%[^,],%d,%d,%[^,],%d", &tmp_sock, tmp_ip, &tmp_port, &tpm_length, resultBuffer, &tpm_length_rem) == 6) { SerialUSB.println(__FILE__": _socketReceiveParser() OK"); int i; for(i=0; i < tpm_length;i++) { parsedBuffer[i] = HEX_PAIR_TO_BYTE(resultBuffer[i*2], resultBuffer[i*2+1]); } -// parsedBuffer[i*2] = 0; + free(resultBuffer); return ResponseEmpty; } SerialUSB.println(__FILE__": _socketReceiveParser() ERR"); + free(resultBuffer); return ResponseError; }