Permalink
Browse files

free the client after close if we can

  • Loading branch information...
1 parent 225ddad commit 7169649857281590f4e2d3d52296d90da06062f3 @brianmario committed Oct 13, 2010
Showing with 8 additions and 1 deletion.
  1. +7 −1 ext/mysql2/client.c
  2. +1 −0 ext/mysql2/client.h
View
@@ -132,7 +132,9 @@ 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);
- free(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;
}
View
@@ -35,6 +35,7 @@ typedef struct {
VALUE encoding;
short int active;
short int closed;
+ short int freed;
MYSQL *client;
} mysql_client_wrapper;

0 comments on commit 7169649

Please sign in to comment.