Skip to content

Commit 584365a

Browse files
shioimmk0kubun
authored andcommitted
Ensure that memory is not freed before calling free_fast_fallback_getaddrinfo_* (ruby#12661)
Ensure that `getaddrinfo_entry` and `getaddrinfo_shared` exist before free them in the main thread.
1 parent 45ddafb commit 584365a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

ext/socket/ipsocket.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,9 +1175,13 @@ fast_fallback_inetsock_cleanup(VALUE v)
11751175
rb_nativethread_lock_unlock(&getaddrinfo_shared->lock);
11761176

11771177
for (int i = 0; i < arg->family_size; i++) {
1178-
if (need_free[i]) free_fast_fallback_getaddrinfo_entry(&arg->getaddrinfo_entries[i]);
1178+
if (arg->getaddrinfo_entries[i] && need_free[i]) {
1179+
free_fast_fallback_getaddrinfo_entry(&arg->getaddrinfo_entries[i]);
1180+
}
1181+
}
1182+
if (getaddrinfo_shared && shared_need_free) {
1183+
free_fast_fallback_getaddrinfo_shared(&getaddrinfo_shared);
11791184
}
1180-
if (shared_need_free) free_fast_fallback_getaddrinfo_shared(&getaddrinfo_shared);
11811185
}
11821186

11831187
int connection_attempt_fd;

0 commit comments

Comments
 (0)