From a42308e28a5f16e8c6391bbd2caa07ece17c5654 Mon Sep 17 00:00:00 2001 From: John Safranek Date: Mon, 26 Oct 2015 12:01:21 -0700 Subject: [PATCH] Add function ssl_FreeDecodeBuffer() to release the sniffer allocated data buffer and reset the pointer. --- src/sniffer.c | 15 +++++++++++++++ sslSniffer/sslSnifferTest/snifftest.c | 3 +-- wolfssl/sniffer.h | 3 +++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/sniffer.c b/src/sniffer.c index e1a57ec1f..3ab4fd96c 100644 --- a/src/sniffer.c +++ b/src/sniffer.c @@ -3229,6 +3229,21 @@ int ssl_DecodePacket(const byte* packet, int length, byte** data, char* error) } +/* Deallocator for the decoded data buffer. */ +/* returns 0 on success, -1 on error */ +int ssl_FreeDecodeBuffer(byte** data, char* error) +{ + (void)error; + + if (data != NULL) { + free(*data); + *data = NULL; + } + + return 0; +} + + /* Enables (if traceFile)/ Disables debug tracing */ /* returns 0 on success, -1 on error */ int ssl_Trace(const char* traceFile, char* error) diff --git a/sslSniffer/sslSnifferTest/snifftest.c b/sslSniffer/sslSnifferTest/snifftest.c index b618eec0c..04ceb5ed9 100755 --- a/sslSniffer/sslSnifferTest/snifftest.c +++ b/sslSniffer/sslSnifferTest/snifftest.c @@ -313,8 +313,7 @@ int main(int argc, char** argv) if (ret > 0) { data[ret] = 0; printf("SSL App Data(%d:%d):%s\n", packetNumber, ret, data); - free(data); - data = NULL; + ssl_FreeDecodeBuffer(&data, err); } } else if (saveFile) diff --git a/wolfssl/sniffer.h b/wolfssl/sniffer.h index 5e626d93f..6b8ae02ee 100644 --- a/wolfssl/sniffer.h +++ b/wolfssl/sniffer.h @@ -58,6 +58,9 @@ WOLFSSL_API SSL_SNIFFER_API int ssl_DecodePacket(const unsigned char* packet, int length, unsigned char** data, char* error); +WOLFSSL_API +SSL_SNIFFER_API int ssl_FreeDecodeBuffer(unsigned char** data, char* error); + WOLFSSL_API SSL_SNIFFER_API int ssl_Trace(const char* traceFile, char* error);