@@ -104,6 +104,10 @@ static void rb_mysql_result_free_result(mysql2_result_wrapper * wrapper) {
104
104
wrapper -> stmt_wrapper -> stmt -> bind_result_done = 0 ;
105
105
}
106
106
107
+ if (wrapper -> statement != Qnil ) {
108
+ decr_mysql2_stmt (wrapper -> stmt_wrapper );
109
+ }
110
+
107
111
if (wrapper -> result_buffers ) {
108
112
unsigned int i ;
109
113
for (i = 0 ; i < wrapper -> numberOfFields ; i ++ ) {
@@ -136,13 +140,15 @@ static void rb_mysql_result_free(void *ptr) {
136
140
decr_mysql2_client (wrapper -> client_wrapper );
137
141
}
138
142
139
- if (wrapper -> statement != Qnil ) {
140
- decr_mysql2_stmt (wrapper -> stmt_wrapper );
141
- }
142
-
143
143
xfree (wrapper );
144
144
}
145
145
146
+ static VALUE rb_mysql_result_free_ (VALUE self ) {
147
+ GET_RESULT (self );
148
+ rb_mysql_result_free_result (wrapper );
149
+ return Qnil ;
150
+ }
151
+
146
152
/*
147
153
* for small results, this won't hit the network, but there's no
148
154
* reliable way for us to tell this so we'll always release the GVL
@@ -511,7 +517,6 @@ static VALUE rb_mysql_result_fetch_row_stmt(VALUE self, MYSQL_FIELD * fields, co
511
517
return rowVal ;
512
518
}
513
519
514
-
515
520
static VALUE rb_mysql_result_fetch_row (VALUE self , MYSQL_FIELD * fields , const result_each_args * args )
516
521
{
517
522
VALUE rowVal ;
@@ -911,6 +916,7 @@ static VALUE rb_mysql_result_each(int argc, VALUE * argv, VALUE self) {
911
916
if (wrapper -> lastRowProcessed == 0 && !wrapper -> is_streaming ) {
912
917
wrapper -> numberOfRows = wrapper -> stmt_wrapper ? mysql_stmt_num_rows (wrapper -> stmt_wrapper -> stmt ) : mysql_num_rows (wrapper -> result );
913
918
if (wrapper -> numberOfRows == 0 ) {
919
+ rb_mysql_result_free_result (wrapper );
914
920
wrapper -> rows = rb_ary_new ();
915
921
return wrapper -> rows ;
916
922
}
@@ -1007,6 +1013,7 @@ void init_mysql2_result() {
1007
1013
cMysql2Result = rb_define_class_under (mMysql2 , "Result" , rb_cObject );
1008
1014
rb_define_method (cMysql2Result , "each" , rb_mysql_result_each , -1 );
1009
1015
rb_define_method (cMysql2Result , "fields" , rb_mysql_result_fetch_fields , 0 );
1016
+ rb_define_method (cMysql2Result , "free" , rb_mysql_result_free_ , 0 );
1010
1017
rb_define_method (cMysql2Result , "count" , rb_mysql_result_count , 0 );
1011
1018
rb_define_alias (cMysql2Result , "size" , "count" );
1012
1019
0 commit comments