This is an automated email from the ASF dual-hosted git repository.
jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
The following commit(s) were added to refs/heads/master by this push:
new 7b29102e8 net/ip/native_sockets: Define static stack for task
7b29102e8 is described below
commit 7b29102e8fe580e537cb97fa8682500e7d97aee3
Author: Mariusz Skamra <[email protected]>
AuthorDate: Fri Feb 14 12:38:07 2025 +0100
net/ip/native_sockets: Define static stack for task
This adds static stack for socket task instead of heap allocated.
This fixes valgrind errors caused by memory leaks as there is no
stack deallocation in this case.
---
net/ip/native_sockets/src/native_sock.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/net/ip/native_sockets/src/native_sock.c
b/net/ip/native_sockets/src/native_sock.c
index 71ad0486b..33a04d5ec 100644
--- a/net/ip/native_sockets/src/native_sock.c
+++ b/net/ip/native_sockets/src/native_sock.c
@@ -37,6 +37,8 @@
#include "native_sock_priv.h"
+OS_TASK_STACK_DEFINE(native_sock_stack, MYNEWT_VAL(NATIVE_SOCKETS_STACK_SZ));
+
static struct native_sock {
struct mn_socket ns_sock;
int ns_fd;
@@ -834,7 +836,6 @@ native_sock_init(void)
{
struct native_sock_state *nss = &native_sock_state;
int i;
- os_stack_t *sp;
/* Ensure this function only gets called by sysinit. */
SYSINIT_ASSERT_ACTIVE();
@@ -843,14 +844,11 @@ native_sock_init(void)
native_socks[i].ns_fd = -1;
STAILQ_INIT(&native_socks[i].ns_rx);
}
- sp = malloc(sizeof(os_stack_t) * MYNEWT_VAL(NATIVE_SOCKETS_STACK_SZ));
- if (!sp) {
- return -1;
- }
+
os_mutex_init(&nss->mtx);
i = os_task_init(&nss->task, "socket", socket_task, &native_sock_state,
- MYNEWT_VAL(NATIVE_SOCKETS_PRIO), OS_WAIT_FOREVER, sp,
- MYNEWT_VAL(NATIVE_SOCKETS_STACK_SZ));
+ MYNEWT_VAL(NATIVE_SOCKETS_PRIO), OS_WAIT_FOREVER,
native_sock_stack,
+ MYNEWT_VAL(NATIVE_SOCKETS_STACK_SZ));
if (i) {
return -1;
}