Skip to content

Commit 88fddbc

Browse files
authored
Guard sql from GC (#1150)
In `rb_mysql_query()`, the raw pointer of the sql string is extracted, and it is passed to `do_send_query()` via `args`. `do_send_query()` internally releases the GVL, then ruby might do GC in the function. Then, the sql string may be GC'ed, and causes SEGV. Therefore, should guard the sql string until `do_send_query()` ends.
1 parent d4bb730 commit 88fddbc

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

ext/mysql2/client.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,7 @@ static VALUE rb_mysql_query(VALUE self, VALUE sql, VALUE current) {
797797

798798
#ifndef _WIN32
799799
rb_rescue2(do_send_query, (VALUE)&args, disconnect_and_raise, self, rb_eException, (VALUE)0);
800+
(void)RB_GC_GUARD(sql);
800801

801802
if (rb_hash_aref(current, sym_async) == Qtrue) {
802803
return Qnil;
@@ -810,6 +811,7 @@ static VALUE rb_mysql_query(VALUE self, VALUE sql, VALUE current) {
810811
}
811812
#else
812813
do_send_query((VALUE)&args);
814+
(void)RB_GC_GUARD(sql);
813815

814816
/* this will just block until the result is ready */
815817
return rb_ensure(rb_mysql_client_async_result, self, disconnect_and_mark_inactive, self);

0 commit comments

Comments
 (0)