Skip to content

Commit

Permalink
Merge pull request #816 from kpumuk/segfault-fix
Browse files Browse the repository at this point in the history
Segfault on SIGINT (race condition)
  • Loading branch information
sodabrew committed Jan 2, 2017
2 parents 301b14b + 9c14d32 commit 458834a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions ext/mysql2/client.c
Expand Up @@ -596,9 +596,11 @@ static VALUE disconnect_and_raise(VALUE self, VALUE error) {
/* Invalidate the MySQL socket to prevent further communication.
* The GC will come along later and call mysql_close to free it.
*/
if (invalidate_fd(wrapper->client->net.fd) == Qfalse) {
fprintf(stderr, "[WARN] mysql2 failed to invalidate FD safely, closing unsafely\n");
close(wrapper->client->net.fd);
if (wrapper->client) {
if (invalidate_fd(wrapper->client->net.fd) == Qfalse) {
fprintf(stderr, "[WARN] mysql2 failed to invalidate FD safely, closing unsafely\n");
close(wrapper->client->net.fd);
}
}

rb_exc_raise(error);
Expand Down

0 comments on commit 458834a

Please sign in to comment.