Skip to content

Commit b16d8db

Browse files
Jari PoyhonenJari Poyhonen
Jari Poyhonen
authored and
Jari Poyhonen
committed
cellular unit test updates due valgrind run
1 parent 007caa0 commit b16d8db

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

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)

0 commit comments

Comments
 (0)