Skip to content

Commit 6aacbd6

Browse files
HParkermame
authored andcommitted
Free pthread_attr after setting up the thread
[bug #20149]
1 parent dd8157f commit 6aacbd6

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

ext/socket/raddrinfo.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,11 @@ rb_getaddrinfo(const char *hostp, const char *portp, const struct addrinfo *hint
511511
}
512512
pthread_detach(th);
513513

514+
int r;
515+
if ((r = pthread_attr_destroy(&attr)) != 0) {
516+
rb_bug_errno("pthread_attr_destroy", r);
517+
}
518+
514519
rb_thread_call_without_gvl2(wait_getaddrinfo, arg, cancel_getaddrinfo, arg);
515520

516521
int need_free = 0;
@@ -732,12 +737,17 @@ rb_getnameinfo(const struct sockaddr *sa, socklen_t salen,
732737
#endif
733738

734739
pthread_t th;
735-
if (do_pthread_create(&th, 0, do_getnameinfo, arg) != 0) {
740+
if (do_pthread_create(&th, &attr, do_getnameinfo, arg) != 0) {
736741
free_getnameinfo_arg(arg);
737742
return EAI_AGAIN;
738743
}
739744
pthread_detach(th);
740745

746+
int r;
747+
if ((r = pthread_attr_destroy(&attr)) != 0) {
748+
rb_bug_errno("pthread_attr_destroy", r);
749+
}
750+
741751
rb_thread_call_without_gvl2(wait_getnameinfo, arg, cancel_getnameinfo, arg);
742752

743753
int need_free = 0;

0 commit comments

Comments
 (0)