Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 763ab07

Browse files
Added freeaddrinfo after getaddrinfo call
1 parent d792cab commit 763ab07

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

‎libraries/SocketWrapper/SocketWrapper.h‎

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class ZephyrSocketWrapper {
2929
// Resolve address
3030
struct addrinfo hints;
3131
struct addrinfo *res;
32+
bool rv = true;
3233

3334
hints.ai_family = AF_INET;
3435
hints.ai_socktype = SOCK_STREAM;
@@ -47,21 +48,31 @@ class ZephyrSocketWrapper {
4748
}
4849

4950
if (ret != 0) {
50-
return false;
51+
rv = false;
52+
goto exit;
5153
}
5254

5355
sock_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
5456
if (sock_fd < 0) {
55-
return false;
57+
rv = false;
58+
59+
goto exit;
5660
}
5761

5862
if (::connect(sock_fd, res->ai_addr, res->ai_addrlen) < 0) {
5963
::close(sock_fd);
6064
sock_fd = -1;
61-
return false;
65+
rv = false;
66+
goto exit;
6267
}
6368

64-
return true;
69+
exit:
70+
if(res != nullptr) {
71+
freeaddrinfo(res);
72+
res = nullptr;
73+
}
74+
75+
return rv;
6576
}
6677

6778
bool connect(IPAddress host, uint16_t port) {
@@ -99,6 +110,13 @@ class ZephyrSocketWrapper {
99110

100111
int resolve_attempts = 100;
101112
int ret;
113+
bool rv = true;
114+
115+
sec_tag_t sec_tag_opt[] = {
116+
CA_CERTIFICATE_TAG,
117+
};
118+
119+
uint32_t timeo_optval = 100;
102120

103121
while (resolve_attempts--) {
104122
ret = getaddrinfo(host, String(port).c_str(), &hints, &res);
@@ -111,7 +129,8 @@ class ZephyrSocketWrapper {
111129
}
112130

113131
if (ret != 0) {
114-
return false;
132+
rv = false;
133+
goto exit;
115134
}
116135

117136
if (ca_certificate_pem != nullptr) {
@@ -121,28 +140,32 @@ class ZephyrSocketWrapper {
121140

122141
sock_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TLS_1_2);
123142
if (sock_fd < 0) {
124-
return false;
143+
rv = false;
144+
goto exit;
125145
}
126146

127-
sec_tag_t sec_tag_opt[] = {
128-
CA_CERTIFICATE_TAG,
129-
};
130147
setsockopt(sock_fd, SOL_TLS, TLS_SEC_TAG_LIST,
131148
sec_tag_opt, sizeof(sec_tag_opt));
132149

133150
setsockopt(sock_fd, SOL_TLS, TLS_HOSTNAME, host, strlen(host));
134151

135-
uint32_t timeo_optval = 100;
136152
setsockopt(sock_fd, SOL_SOCKET, SO_RCVTIMEO, &timeo_optval, sizeof(timeo_optval));
137153

138154
if (::connect(sock_fd, res->ai_addr, res->ai_addrlen) < 0) {
139155
::close(sock_fd);
140156
sock_fd = -1;
141-
return false;
157+
rv = false;
158+
goto exit;
142159
}
143160
is_ssl = true;
144161

145-
return true;
162+
exit:
163+
if(res != nullptr) {
164+
freeaddrinfo(res);
165+
res = nullptr;
166+
}
167+
168+
return rv;
146169
}
147170
#endif
148171

‎loader/llext_exports.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ FORCE_EXPORT_SYM(shared_multi_heap_free);
138138

139139
#if defined(CONFIG_NET_SOCKETS)
140140
FORCE_EXPORT_SYM(getaddrinfo);
141+
FORCE_EXPORT_SYM(freeaddrinfo)
141142
FORCE_EXPORT_SYM(socket);
142143
FORCE_EXPORT_SYM(connect);
143144
FORCE_EXPORT_SYM(send);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /