Skip to content

Commit 50b5f57

Browse files
authored
Merge pull request #9457 from blind-owl/fix_valgrind_defects_from_cellular
Fix valgrind defects from cellular
2 parents 87851f3 + 9f9fce4 commit 50b5f57

File tree

6 files changed

+22
-16
lines changed

6 files changed

+22
-16
lines changed

UNITTESTS/features/cellular/framework/AT/athandler/athandlertest.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ TEST_F(TestATHandler, test_ATHandler_list)
112112
EXPECT_TRUE(at1->close() == NSAPI_ERROR_OK);
113113
EXPECT_TRUE(at2->get_ref_count() == 1);
114114
EXPECT_TRUE(at2->close() == NSAPI_ERROR_OK);
115-
EXPECT_TRUE(at1->close() == NSAPI_ERROR_PARAMETER);
116115

117116
ATHandler::set_at_timeout_list(1000, false);
118117
ATHandler::set_debug_list(false);

UNITTESTS/features/cellular/framework/common/util/utiltest.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,7 @@ TEST_F(Testutil, prefer_ipv6)
138138

139139
TEST_F(Testutil, separate_ip_addresses)
140140
{
141-
char *s = (char *)malloc(128);
142-
141+
char s[128] = {'\0'};
143142
char ip[64] = {0};
144143
char subnet[64] = {0};
145144

UNITTESTS/features/cellular/framework/device/cellulardevice/cellulardevicetest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,11 @@ TEST_F(TestCellularDevice, test_get_context_list)
184184
CellularContext *ctx = dev->create_context();
185185
EXPECT_TRUE(dev->get_context_list());
186186
delete dev;
187-
dev = NULL;
188187

189188
dev = new myCellularDevice(&fh1);
190189
EXPECT_TRUE(dev);
191190
EXPECT_FALSE(dev->get_context_list());
191+
delete dev;
192192
}
193193

194194
TEST_F(TestCellularDevice, test_stop)

UNITTESTS/stubs/ATHandler_stub.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ int ATHandler_stub::int_count = kRead_int_table_size;
5151
bool ATHandler_stub::process_oob_urc = false;
5252

5353
int ATHandler_stub::read_string_index = kRead_string_table_size;
54-
const char *ATHandler_stub::read_string_table[kRead_string_table_size];
54+
const char *ATHandler_stub::read_string_table[kRead_string_table_size] = {'\0'};
5555
int ATHandler_stub::resp_stop_success_count = kResp_stop_count_default;
5656
int ATHandler_stub::urc_amount = 0;
5757
mbed::Callback<void()> ATHandler_stub::callback[kATHandler_urc_table_max_size];
58-
char *ATHandler_stub::urc_string_table[kATHandler_urc_table_max_size];
58+
char *ATHandler_stub::urc_string_table[kATHandler_urc_table_max_size] = {'\0'};
5959

6060
ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, uint32_t timeout, const char *output_delimiter, uint16_t send_delay) :
6161
_nextATHandler(0),

UNITTESTS/stubs/AT_CellularDevice_stub.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ const int DEFAULT_AT_TIMEOUT = 1000;
2424

2525
using namespace mbed;
2626

27-
2827
int AT_CellularDevice_stub::failure_count = 0;
2928
nsapi_error_t AT_CellularDevice_stub::nsapi_error_value = 0;
3029
int AT_CellularDevice_stub::init_module_failure_count = 0;
@@ -33,8 +32,7 @@ int AT_CellularDevice_stub::get_sim_failure_count = 0;
3332
bool AT_CellularDevice_stub::pin_needed = false;
3433

3534
AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : CellularDevice(fh), _network(0), _sms(0),
36-
_information(0), _context_list(0), _default_timeout(DEFAULT_AT_TIMEOUT),
37-
_modem_debug_on(false)
35+
_information(0), _context_list(0), _default_timeout(DEFAULT_AT_TIMEOUT), _modem_debug_on(false)
3836
{
3937
}
4038

@@ -77,7 +75,13 @@ void delete_context(CellularContext *context)
7775

7876
CellularNetwork *AT_CellularDevice::open_network(FileHandle *fh)
7977
{
80-
return new AT_CellularNetwork(*ATHandler::get_instance(fh, _queue, _default_timeout, "\r", get_send_delay(), _modem_debug_on));
78+
_network = new AT_CellularNetwork(*ATHandler::get_instance(fh,
79+
_queue,
80+
_default_timeout,
81+
"\r",
82+
get_send_delay(),
83+
_modem_debug_on));
84+
return _network;
8185
}
8286

8387
CellularSMS *AT_CellularDevice::open_sms(FileHandle *fh)
@@ -92,6 +96,9 @@ CellularInformation *AT_CellularDevice::open_information(FileHandle *fh)
9296

9397
void AT_CellularDevice::close_network()
9498
{
99+
delete _network;
100+
101+
_network = NULL;
95102
}
96103

97104
void AT_CellularDevice::close_sms()
@@ -123,7 +130,9 @@ void AT_CellularDevice::delete_context(CellularContext *context)
123130

124131
AT_CellularNetwork *AT_CellularDevice::open_network_impl(ATHandler &at)
125132
{
126-
return new AT_CellularNetwork(at);
133+
_network = new AT_CellularNetwork(at);
134+
135+
return _network;
127136
}
128137

129138
AT_CellularSMS *AT_CellularDevice::open_sms_impl(ATHandler &at)

features/cellular/framework/AT/ATHandler.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -599,13 +599,11 @@ int32_t ATHandler::read_int()
599599
}
600600

601601
char buff[BUFF_SIZE];
602-
char *first_no_digit;
603-
604-
if (read_string(buff, (size_t)sizeof(buff)) == 0) {
602+
if (read_string(buff, sizeof(buff)) == 0) {
605603
return -1;
606604
}
607605

608-
return std::strtol(buff, &first_no_digit, 10);
606+
return std::strtol(buff, NULL, 10);
609607
}
610608

611609
void ATHandler::set_delimiter(char delimiter)
@@ -1211,8 +1209,9 @@ void ATHandler::debug_print(const char *p, int len)
12111209
#if MBED_CONF_MBED_TRACE_ENABLE
12121210
mbed_cellular_trace::mutex_wait();
12131211
#endif
1212+
char c;
12141213
for (ssize_t i = 0; i < len; i++) {
1215-
char c = *p++;
1214+
c = *p++;
12161215
if (!isprint(c)) {
12171216
if (c == '\r') {
12181217
debug("\n");

0 commit comments

Comments
 (0)