zephyr: lib: sockets: getaddrinfo don't work without newlib C on ARM

Describe the bug The getaddrinfo (zsock_getaddrinfo) method fail with DNS_EAI_MEMORY error at calloc.

from subsys/net/lib/sockets/getaddrinfo.c:

int zsock_getaddrinfo(const char *host, const char *service,
		      const struct zsock_addrinfo *hints,
		      struct zsock_addrinfo **res)
{
	if (IS_ENABLED(CONFIG_NET_SOCKETS_OFFLOAD)) {
		return socket_offload_getaddrinfo(host, service, hints, res);
	}

#if defined(CONFIG_DNS_RESOLVER)
	int ret;

	*res = calloc(AI_ARR_MAX, sizeof(struct zsock_addrinfo));
	if (!(*res)) {
		return DNS_EAI_MEMORY;
	}
	ret = z_zsock_getaddrinfo_internal(host, service, hints, *res);
	if (ret) {
		free(*res);
		*res = NULL;
	}
	return ret;
#endif

	return DNS_EAI_FAIL;
}

To Reproduce Can look at https://github.com/nandojve/zephyr/tree/topic/tagoio_http_post_json project. It is an functional test with TagoIO IoT Platform using HTTP post.

The implementation is in int tagoio_connect(struct tagoio_context_t *ctx) method on socket.c file.

Expected behavior Proper getaddrinfo function working independent of libC.

Impact/workaround Don’t work without add newlib C.

Environment:

  • OS: Linux Debian Buster (10)
  • Toolchain Zephyr SDK 0.11.3
  • Commit SHA or Version used

Additional context I noted that DNS on shell works independent of the lib C used.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 18 (18 by maintainers)

Commits related to this issue

Most upvoted comments

May HEAP_MEM_POOL_SIZE be the right value for MINIMAL_LIBC_MALLOC_ARENA_SIZE?

Hi @cfriedt - yes, it worked thanks for the tip. However after eleven minutes start to got same erro using 16384 for arena. [00:11:18.243,000] <err> tagoio: Could not resolve dns, error: -10 Probably is because not all paths after z_zsock_getaddrinfo_internal free the resource. Yep, I forget to use freeaddrinfo.

I noted that MINIMAL_LIBC_MALLOC default is YES and MINIMAL_LIBC_MALLOC_ARENA_SIZE default is 0 so it will always fail for anyone. Do you know if there is any particular reason to keep default 0? I’m not understand the purpose to enable malloc by default without valid arena.