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:
parent
757303fe8d
commit
e20904d7cf
Notes:
git
2024-12-03 18:04:36 +00:00
@ -309,7 +309,7 @@ cancel_fast_fallback(void *ptr)
|
|||||||
|
|
||||||
struct fast_fallback_getaddrinfo_shared *arg = (struct fast_fallback_getaddrinfo_shared *)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;
|
arg->cancelled = true;
|
||||||
char notification = SELECT_CANCELLED;
|
char notification = SELECT_CANCELLED;
|
||||||
@ -317,7 +317,7 @@ cancel_fast_fallback(void *ptr)
|
|||||||
rb_syserr_fail(errno, "write(2)");
|
rb_syserr_fail(errno, "write(2)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rb_nativethread_lock_unlock(arg->lock);
|
rb_nativethread_lock_unlock(&arg->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct hostname_resolution_result
|
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);
|
arg->getaddrinfo_shared = allocate_fast_fallback_getaddrinfo_shared(arg->family_size);
|
||||||
if (!arg->getaddrinfo_shared) rb_syserr_fail(errno, "calloc(3)");
|
if (!arg->getaddrinfo_shared) rb_syserr_fail(errno, "calloc(3)");
|
||||||
|
|
||||||
arg->getaddrinfo_shared->lock = calloc(1, sizeof(rb_nativethread_lock_t));
|
rb_nativethread_lock_initialize(&arg->getaddrinfo_shared->lock);
|
||||||
if (!arg->getaddrinfo_shared->lock) rb_syserr_fail(errno, "calloc(3)");
|
|
||||||
rb_nativethread_lock_initialize(arg->getaddrinfo_shared->lock);
|
|
||||||
|
|
||||||
arg->getaddrinfo_shared->notify = hostname_resolution_notifier;
|
arg->getaddrinfo_shared->notify = hostname_resolution_notifier;
|
||||||
arg->getaddrinfo_shared->cancelled = false;
|
arg->getaddrinfo_shared->cancelled = false;
|
||||||
@ -1198,7 +1196,7 @@ fast_fallback_inetsock_cleanup(VALUE v)
|
|||||||
int shared_need_free = 0;
|
int shared_need_free = 0;
|
||||||
int need_free[2] = { 0, 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++) {
|
for (int i = 0; i < arg->family_size; i++) {
|
||||||
if (arg->getaddrinfo_entries[i] && --(arg->getaddrinfo_entries[i]->refcount) == 0) {
|
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;
|
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++) {
|
for (int i = 0; i < arg->family_size; i++) {
|
||||||
if (need_free[i]) free_fast_fallback_getaddrinfo_entry(&arg->getaddrinfo_entries[i]);
|
if (need_free[i]) free_fast_fallback_getaddrinfo_entry(&arg->getaddrinfo_entries[i]);
|
||||||
|
@ -3033,7 +3033,7 @@ free_fast_fallback_getaddrinfo_shared(struct fast_fallback_getaddrinfo_shared **
|
|||||||
(*shared)->node = NULL;
|
(*shared)->node = NULL;
|
||||||
free((*shared)->service);
|
free((*shared)->service);
|
||||||
(*shared)->service = NULL;
|
(*shared)->service = NULL;
|
||||||
rb_nativethread_lock_destroy((*shared)->lock);
|
rb_nativethread_lock_destroy(&(*shared)->lock);
|
||||||
free(*shared);
|
free(*shared);
|
||||||
*shared = NULL;
|
*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;
|
entry->err = err;
|
||||||
if (shared->cancelled) {
|
if (shared->cancelled) {
|
||||||
@ -3112,7 +3112,7 @@ do_fast_fallback_getaddrinfo(void *ptr)
|
|||||||
if (--(entry->refcount) == 0) need_free = 1;
|
if (--(entry->refcount) == 0) need_free = 1;
|
||||||
if (--(shared->refcount) == 0) shared_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) {
|
if (need_free && entry) {
|
||||||
free_fast_fallback_getaddrinfo_entry(&entry);
|
free_fast_fallback_getaddrinfo_entry(&entry);
|
||||||
|
@ -443,7 +443,7 @@ struct fast_fallback_getaddrinfo_shared
|
|||||||
int notify, refcount;
|
int notify, refcount;
|
||||||
int cancelled;
|
int cancelled;
|
||||||
char *node, *service;
|
char *node, *service;
|
||||||
rb_nativethread_lock_t *lock;
|
rb_nativethread_lock_t lock;
|
||||||
struct fast_fallback_getaddrinfo_entry getaddrinfo_entries[FLEX_ARY_LEN];
|
struct fast_fallback_getaddrinfo_entry getaddrinfo_entries[FLEX_ARY_LEN];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user