@@ -182,15 +182,14 @@ static VALUE nogvl_close(void *ptr) {
182
182
return Qnil ;
183
183
}
184
184
185
- static void rb_mysql_client_free (void * ptr ) {
185
+ static void rb_mysql_client_free (void * ptr ) {
186
186
mysql_client_wrapper * wrapper = (mysql_client_wrapper * )ptr ;
187
187
188
- wrapper -> freed = 1 ;
189
- nogvl_close (wrapper );
190
-
188
+ wrapper -> refcount -- ;
191
189
if (wrapper -> refcount == 0 ) {
190
+ nogvl_close (wrapper );
192
191
xfree (wrapper -> client );
193
- xfree (ptr );
192
+ xfree (wrapper );
194
193
}
195
194
}
196
195
@@ -203,8 +202,7 @@ static VALUE allocate(VALUE klass) {
203
202
wrapper -> reconnect_enabled = 0 ;
204
203
wrapper -> connected = 0 ; /* means that a database connection is open */
205
204
wrapper -> initialized = 0 ; /* means that that the wrapper is initialized */
206
- wrapper -> refcount = 0 ;
207
- wrapper -> freed = 0 ;
205
+ wrapper -> refcount = 1 ;
208
206
wrapper -> client = (MYSQL * )xmalloc (sizeof (MYSQL ));
209
207
return obj ;
210
208
}
@@ -366,9 +364,6 @@ static VALUE nogvl_use_result(void *ptr) {
366
364
static VALUE rb_mysql_client_async_result (VALUE self ) {
367
365
MYSQL_RES * result ;
368
366
VALUE resultObj ;
369
- #ifdef HAVE_RUBY_ENCODING_H
370
- mysql2_result_wrapper * result_wrapper ;
371
- #endif
372
367
GET_CLIENT (self );
373
368
374
369
/* if we're not waiting on a result, do nothing */
@@ -398,14 +393,7 @@ static VALUE rb_mysql_client_async_result(VALUE self) {
398
393
return Qnil ;
399
394
}
400
395
401
- resultObj = rb_mysql_result_to_obj (wrapper , result );
402
- /* pass-through query options for result construction later */
403
- rb_iv_set (resultObj , "@query_options" , rb_hash_dup (rb_iv_get (self , "@current_query_options" )));
404
-
405
- #ifdef HAVE_RUBY_ENCODING_H
406
- GetMysql2Result (resultObj , result_wrapper );
407
- result_wrapper -> encoding = wrapper -> encoding ;
408
- #endif
396
+ resultObj = rb_mysql_result_to_obj (self , wrapper -> encoding , rb_hash_dup (rb_iv_get (self , "@current_query_options" )), result );
409
397
return resultObj ;
410
398
}
411
399
@@ -931,10 +919,6 @@ static VALUE rb_mysql_client_store_result(VALUE self)
931
919
{
932
920
MYSQL_RES * result ;
933
921
VALUE resultObj ;
934
- #ifdef HAVE_RUBY_ENCODING_H
935
- mysql2_result_wrapper * result_wrapper ;
936
- #endif
937
-
938
922
GET_CLIENT (self );
939
923
940
924
result = (MYSQL_RES * )rb_thread_blocking_region (nogvl_store_result , wrapper , RUBY_UBF_IO , 0 );
@@ -947,14 +931,7 @@ static VALUE rb_mysql_client_store_result(VALUE self)
947
931
return Qnil ;
948
932
}
949
933
950
- resultObj = rb_mysql_result_to_obj (wrapper , result );
951
- /* pass-through query options for result construction later */
952
- rb_iv_set (resultObj , "@query_options" , rb_hash_dup (rb_iv_get (self , "@current_query_options" )));
953
-
954
- #ifdef HAVE_RUBY_ENCODING_H
955
- GetMysql2Result (resultObj , result_wrapper );
956
- result_wrapper -> encoding = wrapper -> encoding ;
957
- #endif
934
+ resultObj = rb_mysql_result_to_obj (self , wrapper -> encoding , rb_hash_dup (rb_iv_get (self , "@current_query_options" )), result );
958
935
return resultObj ;
959
936
960
937
}
0 commit comments