Skip to content

Commit 4e5ea38

Browse files
nsapi_dns: use delete[] for array alloc'd with new[]
1 parent a26d2d9 commit 4e5ea38

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

UNITTESTS/features/netsocket/nsapi_dns/test_nsapi_dns.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,9 @@ TEST_F(Test_nsapi_dns, single_query)
331331
.WillOnce(DoAll(SetArgPointee<0>((void **)&NetworkStackMock::get_instance()), Return(NSAPI_ERROR_OK)));
332332

333333
// Returning UNSUPPORTED will cause the nsapi_dns addresses to be used.
334-
EXPECT_CALL(*((NetworkStackMock *)iface->get_stack()), get_dns_server(_, _, _)).Times(1).WillOnce(Return(NSAPI_ERROR_OK));
334+
EXPECT_CALL(*((NetworkStackMock *)iface->get_stack()), get_dns_server(_, _, _))
335+
.Times(1)
336+
.WillOnce(DoAll(SetArgPointee<1>(SocketAddress("1.2.3.4", 53)), Return(NSAPI_ERROR_OK)));
335337

336338
EXPECT_CALL(*((NetworkStackMock *)iface->get_stack()), socket_sendto(_, _, _, _)).Times(1).WillOnce(Return(NSAPI_ERROR_OK));
337339

@@ -419,6 +421,7 @@ TEST_F(Test_nsapi_dns, multiple_queries)
419421
EXPECT_FALSE(strncmp(addr[1].get_ip_address(), "222.173.190.239", sizeof("222.173.190.239")));
420422
EXPECT_EQ(addr[2].get_ip_version(), NSAPI_IPv4);
421423
EXPECT_FALSE(strncmp(addr[2].get_ip_address(), "1.2.3.4", sizeof("1.2.3.4")));
424+
delete[] addr;
422425

423426
SocketAddress *addr_cache;
424427
// Cache will only raturn one address.
@@ -427,6 +430,7 @@ TEST_F(Test_nsapi_dns, multiple_queries)
427430
// This is a bug which will be fixed in
428431
EXPECT_EQ(addr_cache[0].get_ip_version(), NSAPI_IPv4);
429432
EXPECT_FALSE(strncmp(addr_cache[0].get_ip_address(), "216.58.207.238", sizeof("216.58.207.238")));
433+
delete[] addr_cache;
430434
}
431435

432436
TEST_F(Test_nsapi_dns, single_query_errors)

UNITTESTS/features/netsocket/nsapi_dns/unittest.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ set(unittest-test-sources
2626
stubs/NetworkInterfaceDefaults_stub.cpp
2727
stubs/mbed_atomic_stub.c
2828
stubs/mbed_critical_stub.c
29+
stubs/mbed_rtos_rtx_stub.c
2930
stubs/Kernel_stub.cpp
30-
#stubs/mbed_error.c
31-
#stubs/mbed_shared_queues_stub.cpp
32-
#InternetSocket.cpp:
3331
stubs/EventFlags_stub.cpp
32+
stubs/rtx_mutex_stub.c
3433
stubs/SocketStats_Stub.cpp
3534
features/netsocket/nsapi_dns/test_nsapi_dns.cpp
3635
../features/netsocket/NetworkInterface.cpp
3736
../features/netsocket/InternetSocket.cpp
37+
../features/netsocket/InternetDatagramSocket.cpp
3838
../features/netsocket/UDPSocket.cpp
3939
)
4040

features/netsocket/nsapi_dns.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ static void nsapi_dns_cache_reset()
411411
dns_cache_mutex->lock();
412412
for (int i = 0; i < MBED_CONF_NSAPI_DNS_CACHE_SIZE; i++) {
413413
if (dns_cache[i]) {
414-
delete dns_cache[i]->host;
414+
delete[] dns_cache[i]->host;
415415
dns_cache[i]->host = NULL;
416416
delete dns_cache[i];
417417
dns_cache[i] = NULL;
@@ -984,7 +984,7 @@ static nsapi_error_t nsapi_dns_query_async_delete(intptr_t unique_id)
984984
delete[] query->addrs;
985985
}
986986

987-
delete query->host;
987+
delete[] query->host;
988988
delete query;
989989
dns_query_queue[index] = NULL;
990990

0 commit comments

Comments
 (0)