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. */
|
/* It's safe to call mysql_close() on an already closed connection. */
|
||||||
if (!wrapper->closed) {
|
if (!wrapper->closed) {
|
||||||
mysql_close(wrapper->client);
|
mysql_close(wrapper->client);
|
||||||
|
if (!wrapper->freed) {
|
||||||
free(wrapper->client);
|
free(wrapper->client);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
xfree(ptr);
|
xfree(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,6 +144,9 @@ static VALUE nogvl_close(void * ptr) {
|
|||||||
if (!wrapper->closed) {
|
if (!wrapper->closed) {
|
||||||
mysql_close(wrapper->client);
|
mysql_close(wrapper->client);
|
||||||
wrapper->closed = 1;
|
wrapper->closed = 1;
|
||||||
|
if (!wrapper->freed) {
|
||||||
|
free(wrapper->client);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
@ -153,6 +158,7 @@ static VALUE allocate(VALUE klass) {
|
|||||||
wrapper->encoding = Qnil;
|
wrapper->encoding = Qnil;
|
||||||
wrapper->active = 0;
|
wrapper->active = 0;
|
||||||
wrapper->closed = 0;
|
wrapper->closed = 0;
|
||||||
|
wrapper->freed = 0;
|
||||||
wrapper->client = (MYSQL*)malloc(sizeof(MYSQL));
|
wrapper->client = (MYSQL*)malloc(sizeof(MYSQL));
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,7 @@ typedef struct {
|
|||||||
VALUE encoding;
|
VALUE encoding;
|
||||||
short int active;
|
short int active;
|
||||||
short int closed;
|
short int closed;
|
||||||
|
short int freed;
|
||||||
MYSQL *client;
|
MYSQL *client;
|
||||||
} mysql_client_wrapper;
|
} mysql_client_wrapper;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user