From 9229aba87d1cdb24b07c3af9d7dbef9d561c4fa6 Mon Sep 17 00:00:00 2001 From: Hasnain Virk Date: Tue, 9 Apr 2019 12:22:34 +0300 Subject: [PATCH] Using new rather than malloc in debug_print Using malloc will require us to add stdlib.h somewhere in the path for the application. Maybe the CI apps are adding stdlib.h and that's why the code would have worked. In a custom app, it can happen that the header is not included. Using new avoids the need to add stdlib.h anywhere and it is more in line with C++. --- features/cellular/framework/AT/ATHandler.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/features/cellular/framework/AT/ATHandler.cpp b/features/cellular/framework/AT/ATHandler.cpp index e7d366ca385..cd2d7c3c8aa 100644 --- a/features/cellular/framework/AT/ATHandler.cpp +++ b/features/cellular/framework/AT/ATHandler.cpp @@ -1289,7 +1289,7 @@ void ATHandler::debug_print(const char *p, int len, ATType type) #if MBED_CONF_CELLULAR_DEBUG_AT if (_debug_on) { const int buf_size = len * 4 + 1; // x4 -> reserve space for extra characters, +1 -> terminating null - char *buffer = (char *)malloc(buf_size); + char *buffer = new char [buf_size]; if (buffer) { memset(buffer, 0, buf_size); @@ -1319,7 +1319,7 @@ void ATHandler::debug_print(const char *p, int len, ATType type) tr_info("AT ERR (%2d): %s", len, buffer); } - free(buffer); + delete [] buffer; } else { tr_error("AT trace unable to allocate buffer!"); }