Use ruby_strdup/xfree in fast_fallback

Any memory allocated with xmalloc needs to be matched with xfree rather
than plain free.

Ruby unfortunately redefines strdup to be ruby_strdup, which uses
xmalloc so needs to be xfreed. Previously these were mismatched.

This commit changes the copy to be an explicit ruby_strdup (to avoid
confusion) and the free to be xfree.
This commit is contained in:
John Hawthorn 2024-12-11 14:44:50 -08:00
parent 9fe6fd8693
commit d84859061a
Notes: git 2024-12-11 23:37:49 +00:00
2 changed files with 4 additions and 4 deletions

View File

@ -592,8 +592,8 @@ init_fast_fallback_inetsock_internal(VALUE v)
rb_nativethread_lock_initialize(&arg->getaddrinfo_shared->lock);
arg->getaddrinfo_shared->notify = hostname_resolution_notifier;
arg->getaddrinfo_shared->node = arg->hostp ? strdup(arg->hostp) : NULL;
arg->getaddrinfo_shared->service = strdup(arg->portp);
arg->getaddrinfo_shared->node = arg->hostp ? ruby_strdup(arg->hostp) : NULL;
arg->getaddrinfo_shared->service = ruby_strdup(arg->portp);
arg->getaddrinfo_shared->refcount = arg->family_size + 1;
for (int i = 0; i < arg->family_size; i++) {

View File

@ -3029,9 +3029,9 @@ rsock_io_socket_addrinfo(VALUE io, struct sockaddr *addr, socklen_t len)
void
free_fast_fallback_getaddrinfo_shared(struct fast_fallback_getaddrinfo_shared **shared)
{
free((*shared)->node);
xfree((*shared)->node);
(*shared)->node = NULL;
free((*shared)->service);
xfree((*shared)->service);
(*shared)->service = NULL;
rb_nativethread_lock_destroy(&(*shared)->lock);
free(*shared);