Skip to content

Commit

Permalink
free the client after close if we can
Browse files Browse the repository at this point in the history
  • Loading branch information
brianmario committed Oct 13, 2010
1 parent 225ddad commit 7169649
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ext/mysql2/client.c
Expand Up @@ -132,7 +132,9 @@ 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);
free(wrapper->client); if (!wrapper->freed) {
free(wrapper->client);
}
} }
xfree(ptr); xfree(ptr);
} }
Expand All @@ -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;
} }
Expand All @@ -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;
} }
Expand Down
1 change: 1 addition & 0 deletions ext/mysql2/client.h
Expand Up @@ -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;


Expand Down

0 comments on commit 7169649

Please sign in to comment.