Skip to content

Commit 052ff38

Browse files
juhaylinenSeppoTakalo
authored andcommitted
net: nrf_provisioning: Fix memory leak
Free results from zsock_getaddrinfo(). Signed-off-by: Juha Ylinen <[email protected]>
1 parent 4b2712e commit 052ff38

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

subsys/net/lib/nrf_provisioning/src/nrf_provisioning_coap.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ LOG_MODULE_REGISTER(nrf_provisioning_coap, CONFIG_NRF_PROVISIONING_LOG_LEVEL);
5555
static const char *resp_path = "p/rsp";
5656
static const char *dtls_suspend = "/.dtls/suspend";
5757

58-
static struct zsock_addrinfo *address;
5958
static struct coap_client client;
6059
static bool socket_keep_open;
6160

@@ -169,7 +168,8 @@ static int dtls_setup(int fd)
169168

170169
static int socket_connect(int *const fd)
171170
{
172-
static struct zsock_addrinfo hints;
171+
struct zsock_addrinfo hints = {};
172+
struct zsock_addrinfo *address = NULL;
173173
int st;
174174
int ret = 0;
175175
struct sockaddr *sa;
@@ -226,6 +226,10 @@ static int socket_connect(int *const fd)
226226

227227
clean_up:
228228

229+
if (address) {
230+
zsock_freeaddrinfo(address);
231+
}
232+
229233
if (ret) {
230234
if (*fd > -1) {
231235
(void)zsock_close(*fd);

tests/subsys/net/lib/nrf_provisioning/src/coap.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ int zsock_getaddrinfo(const char *host, const char *service, const struct zsock_
113113
return 0;
114114
}
115115

116+
void zsock_freeaddrinfo(struct zsock_addrinfo *ai)
117+
{
118+
}
119+
116120
int z_impl_zsock_connect(int sock, const struct sockaddr *addr, socklen_t addrlen)
117121
{
118122
return 0;

0 commit comments

Comments
 (0)