Fix use of getaddrinfo_shared->lock

In some locations we were using shared->lock and in others
&shared->lock, and we were leaking the allocated memory.
This commit is contained in:
John Hawthorn 2024-12-02 19:41:12 -08:00
parent 757303fe8d
commit e20904d7cf
Notes: git 2024-12-03 18:04:36 +00:00
3 changed files with 9 additions and 11 deletions

View File

@ -309,7 +309,7 @@ cancel_fast_fallback(void *ptr)
struct fast_fallback_getaddrinfo_shared *arg = (struct fast_fallback_getaddrinfo_shared *)ptr;
rb_nativethread_lock_lock(arg->lock);
rb_nativethread_lock_lock(&arg->lock);
{
arg->cancelled = true;
char notification = SELECT_CANCELLED;
@ -317,7 +317,7 @@ cancel_fast_fallback(void *ptr)
rb_syserr_fail(errno, "write(2)");
}
}
rb_nativethread_lock_unlock(arg->lock);
rb_nativethread_lock_unlock(&arg->lock);
}
struct hostname_resolution_result
@ -595,9 +595,7 @@ init_fast_fallback_inetsock_internal(VALUE v)
arg->getaddrinfo_shared = allocate_fast_fallback_getaddrinfo_shared(arg->family_size);
if (!arg->getaddrinfo_shared) rb_syserr_fail(errno, "calloc(3)");
arg->getaddrinfo_shared->lock = calloc(1, sizeof(rb_nativethread_lock_t));
if (!arg->getaddrinfo_shared->lock) rb_syserr_fail(errno, "calloc(3)");
rb_nativethread_lock_initialize(arg->getaddrinfo_shared->lock);
rb_nativethread_lock_initialize(&arg->getaddrinfo_shared->lock);
arg->getaddrinfo_shared->notify = hostname_resolution_notifier;
arg->getaddrinfo_shared->cancelled = false;
@ -1198,7 +1196,7 @@ fast_fallback_inetsock_cleanup(VALUE v)
int shared_need_free = 0;
int need_free[2] = { 0, 0 };
rb_nativethread_lock_lock(getaddrinfo_shared->lock);
rb_nativethread_lock_lock(&getaddrinfo_shared->lock);
{
for (int i = 0; i < arg->family_size; i++) {
if (arg->getaddrinfo_entries[i] && --(arg->getaddrinfo_entries[i]->refcount) == 0) {
@ -1209,7 +1207,7 @@ fast_fallback_inetsock_cleanup(VALUE v)
shared_need_free = 1;
}
}
rb_nativethread_lock_unlock(getaddrinfo_shared->lock);
rb_nativethread_lock_unlock(&getaddrinfo_shared->lock);
for (int i = 0; i < arg->family_size; i++) {
if (need_free[i]) free_fast_fallback_getaddrinfo_entry(&arg->getaddrinfo_entries[i]);

View File

@ -3033,7 +3033,7 @@ free_fast_fallback_getaddrinfo_shared(struct fast_fallback_getaddrinfo_shared **
(*shared)->node = NULL;
free((*shared)->service);
(*shared)->service = NULL;
rb_nativethread_lock_destroy((*shared)->lock);
rb_nativethread_lock_destroy(&(*shared)->lock);
free(*shared);
*shared = NULL;
}
@ -3092,7 +3092,7 @@ do_fast_fallback_getaddrinfo(void *ptr)
}
}
rb_nativethread_lock_lock(shared->lock);
rb_nativethread_lock_lock(&shared->lock);
{
entry->err = err;
if (shared->cancelled) {
@ -3112,7 +3112,7 @@ do_fast_fallback_getaddrinfo(void *ptr)
if (--(entry->refcount) == 0) need_free = 1;
if (--(shared->refcount) == 0) shared_need_free = 1;
}
rb_nativethread_lock_unlock(shared->lock);
rb_nativethread_lock_unlock(&shared->lock);
if (need_free && entry) {
free_fast_fallback_getaddrinfo_entry(&entry);

View File

@ -443,7 +443,7 @@ struct fast_fallback_getaddrinfo_shared
int notify, refcount;
int cancelled;
char *node, *service;
rb_nativethread_lock_t *lock;
rb_nativethread_lock_t lock;
struct fast_fallback_getaddrinfo_entry getaddrinfo_entries[FLEX_ARY_LEN];
};