Skip to content

Commit

Permalink
Avoid GC run between mysql_stmt_execute and mysql_stmt_store_result
Browse files Browse the repository at this point in the history
This fixes a regression caused by brianmario#912 due to calling `rb_funcall`
between `mysql_stmt_execute` and `mysql_stmt_store_result`, it will
cause `mysql_stmt_close` to be called in wrong order.

Fixes brianmario#956.
  • Loading branch information
kamipo committed Apr 4, 2018
1 parent bf227ac commit 8ddfe12
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions ext/mysql2/statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,12 +426,12 @@ static VALUE rb_mysql_stmt_execute(int argc, VALUE *argv, VALUE self) {
(void)RB_GC_GUARD(current);
Check_Type(current, T_HASH);

// Merge in hash opts/keyword arguments
if (!NIL_P(opts)) {
rb_funcall(current, intern_merge_bang, 1, opts);
is_streaming = (Qtrue == rb_hash_aref(current, sym_stream));

if (!is_streaming && !NIL_P(opts)) {
is_streaming = (Qtrue == rb_hash_aref(opts, sym_stream));
}

is_streaming = (Qtrue == rb_hash_aref(current, sym_stream));
if (!is_streaming) {
// recieve the whole result set from the server
if (mysql_stmt_store_result(stmt)) {
Expand All @@ -441,6 +441,11 @@ static VALUE rb_mysql_stmt_execute(int argc, VALUE *argv, VALUE self) {
wrapper->active_thread = Qnil;
}

// Merge in hash opts/keyword arguments
if (!NIL_P(opts)) {
rb_funcall(current, intern_merge_bang, 1, opts);
}

resultObj = rb_mysql_result_to_obj(stmt_wrapper->client, wrapper->encoding, current, metadata, self);

rb_mysql_set_server_query_flags(wrapper->client, resultObj);
Expand Down

0 comments on commit 8ddfe12

Please sign in to comment.