Skip to content

Commit 9229aba

Browse files
author
Hasnain Virk
committed
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++.
1 parent 65ada92 commit 9229aba

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

features/cellular/framework/AT/ATHandler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,7 @@ void ATHandler::debug_print(const char *p, int len, ATType type)
12891289
#if MBED_CONF_CELLULAR_DEBUG_AT
12901290
if (_debug_on) {
12911291
const int buf_size = len * 4 + 1; // x4 -> reserve space for extra characters, +1 -> terminating null
1292-
char *buffer = (char *)malloc(buf_size);
1292+
char *buffer = new char [buf_size];
12931293
if (buffer) {
12941294
memset(buffer, 0, buf_size);
12951295

@@ -1319,7 +1319,7 @@ void ATHandler::debug_print(const char *p, int len, ATType type)
13191319
tr_info("AT ERR (%2d): %s", len, buffer);
13201320
}
13211321

1322-
free(buffer);
1322+
delete [] buffer;
13231323
} else {
13241324
tr_error("AT trace unable to allocate buffer!");
13251325
}

0 commit comments

Comments
 (0)