free the client after close if we can
This commit is contained in:
parent
225ddadaf7
commit
7169649857
@ -132,8 +132,10 @@ static void rb_mysql_client_free(void * ptr) {
|
||||
/* It's safe to call mysql_close() on an already closed connection. */
|
||||
if (!wrapper->closed) {
|
||||
mysql_close(wrapper->client);
|
||||
if (!wrapper->freed) {
|
||||
free(wrapper->client);
|
||||
}
|
||||
}
|
||||
xfree(ptr);
|
||||
}
|
||||
|
||||
@ -142,6 +144,9 @@ static VALUE nogvl_close(void * ptr) {
|
||||
if (!wrapper->closed) {
|
||||
mysql_close(wrapper->client);
|
||||
wrapper->closed = 1;
|
||||
if (!wrapper->freed) {
|
||||
free(wrapper->client);
|
||||
}
|
||||
}
|
||||
return Qnil;
|
||||
}
|
||||
@ -153,6 +158,7 @@ static VALUE allocate(VALUE klass) {
|
||||
wrapper->encoding = Qnil;
|
||||
wrapper->active = 0;
|
||||
wrapper->closed = 0;
|
||||
wrapper->freed = 0;
|
||||
wrapper->client = (MYSQL*)malloc(sizeof(MYSQL));
|
||||
return obj;
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ typedef struct {
|
||||
VALUE encoding;
|
||||
short int active;
|
||||
short int closed;
|
||||
short int freed;
|
||||
MYSQL *client;
|
||||
} mysql_client_wrapper;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user