prevent the GC from freeing a connection that hasn't been allocated yet

This commit is contained in:
Brian Lopez 2010-10-17 17:35:41 -07:00
parent 410e914411
commit 3c6959a8bb

View File

@ -153,7 +153,7 @@ static VALUE allocate(VALUE klass) {
obj = Data_Make_Struct(klass, mysql_client_wrapper, rb_mysql_client_mark, rb_mysql_client_free, wrapper); obj = Data_Make_Struct(klass, mysql_client_wrapper, rb_mysql_client_mark, rb_mysql_client_free, wrapper);
wrapper->encoding = Qnil; wrapper->encoding = Qnil;
wrapper->active = 0; wrapper->active = 0;
wrapper->closed = 0; wrapper->closed = 1;
wrapper->client = (MYSQL*)malloc(sizeof(MYSQL)); wrapper->client = (MYSQL*)malloc(sizeof(MYSQL));
return obj; return obj;
} }
@ -517,6 +517,7 @@ static VALUE init_connection(VALUE self) {
return rb_raise_mysql2_error(wrapper->client); return rb_raise_mysql2_error(wrapper->client);
} }
wrapper->closed = 0;
return self; return self;
} }