diff --git a/CHANGELOG.md b/CHANGELOG.md index e8c0b5a1..23669780 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## (unreleased) * Add Ruby 3.0 to the cross compile list +* Fix segfault when asking if client was dead after closing it. Fixes #519. ## 2.1.5 diff --git a/ext/tiny_tds/client.c b/ext/tiny_tds/client.c index 1fb0ba6e..ea01d144 100644 --- a/ext/tiny_tds/client.c +++ b/ext/tiny_tds/client.c @@ -232,6 +232,7 @@ static void rb_tinytds_client_free(void *ptr) { dbloginfree(cwrap->login); if (cwrap->client && !cwrap->closed) { dbclose(cwrap->client); + cwrap->client = NULL; cwrap->closed = 1; cwrap->userdata->closed = 1; } @@ -263,6 +264,7 @@ static VALUE rb_tinytds_close(VALUE self) { GET_CLIENT_WRAPPER(self); if (cwrap->client && !cwrap->closed) { dbclose(cwrap->client); + cwrap->client = NULL; cwrap->closed = 1; cwrap->userdata->closed = 1; } diff --git a/test/client_test.rb b/test/client_test.rb index de988d6e..d095db71 100644 --- a/test/client_test.rb +++ b/test/client_test.rb @@ -16,6 +16,7 @@ class ClientTest < TinyTds::TestCase assert @client.close assert @client.closed? assert !@client.active? + assert @client.dead? action = lambda { @client.execute('SELECT 1 as [one]').each } assert_raise_tinytds_error(action) do |e| assert_match %r{closed connection}i, e.message, 'ignore if non-english test run'