From 0f2eeff2438dad088a6ebf7aa87e3f2084aef380 Mon Sep 17 00:00:00 2001 From: vraatikka Date: Mon, 14 Oct 2013 13:16:33 +0300 Subject: [PATCH] gw_buffer was not freed. --- server/include/buffer.h | 33 +++++++++++++------------- server/modules/protocol/mysql_client.c | 6 +++++ server/modules/protocol/mysql_common.c | 1 + 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/server/include/buffer.h b/server/include/buffer.h index d48ae8ee7..e4ecc3409 100644 --- a/server/include/buffer.h +++ b/server/include/buffer.h @@ -61,28 +61,27 @@ typedef struct { * be copied within the gateway. */ typedef struct gwbuf { - struct gwbuf *next; /**< Next buffer in a linked chain of buffers */ - void *start; /**< Start of the valid data */ - void *end; /**< First byte after the valid data */ - SHARED_BUF *sbuf; /**< The shared buffer with the real data */ - int command; /**< The command type for the queue */ + struct gwbuf *next; /**< Next buffer in a linked chain of buffers */ + void *start; /**< Start of the valid data */ + void *end; /**< First byte after the valid data */ + SHARED_BUF *sbuf; /**< The shared buffer with the real data */ + int command;/**< The command type for the queue */ } GWBUF; /* * Macros to access the data in the buffers */ -#define GWBUF_DATA(b) ((b)->start) /**< First valid, uncomsumed - * byte in the buffer - */ -#define GWBUF_LENGTH(b) ((b)->end - (b)->start) /**< Number of bytes in the - * individual buffer - */ -#define GWBUF_EMPTY(b) ((b)->start == (b)->end) /**< True if all bytes in the - * buffer have been consumed - */ -#define GWBUF_CONSUME(b, bytes) (b)->start += bytes /**< Consume a number of bytes - * in the buffer - */ +/**< First valid, uncomsumed byte in the buffer */ +#define GWBUF_DATA(b) ((b)->start) + +/**< Number of bytes in the individual buffer */ +#define GWBUF_LENGTH(b) ((b)->end - (b)->start) + +/**< True if all bytes in the buffer have been consumed */ +#define GWBUF_EMPTY(b) ((b)->start == (b)->end) + +/**< Consume a number of bytes in the buffer */ +#define GWBUF_CONSUME(b, bytes) (b)->start += bytes /* * Function prototypes for the API to maniplate the buffers diff --git a/server/modules/protocol/mysql_client.c b/server/modules/protocol/mysql_client.c index 9e49ae319..ccd810e51 100644 --- a/server/modules/protocol/mysql_client.c +++ b/server/modules/protocol/mysql_client.c @@ -661,6 +661,7 @@ int gw_read_client_event(DCB* dcb) { * Read all the data that is available into a chain of buffers */ { + int len = -1; GWBUF *queue = NULL; GWBUF *gw_buffer = NULL; uint8_t *ptr_buff = NULL; @@ -688,6 +689,7 @@ int gw_read_client_event(DCB* dcb) { /* Now, we are assuming in the first buffer there is * the information form mysql command */ queue = gw_buffer; + len = GWBUF_LENGTH(queue); ptr_buff = GWBUF_DATA(queue); /* get mysql commang at fifth byte */ @@ -721,6 +723,8 @@ int gw_read_client_event(DCB* dcb) { protocol->state = MYSQL_IDLE; } rc = 1; + /** Free buffer */ + queue = gwbuf_consume(queue, len); goto return_rc; } /** Route COM_QUIT to backend */ @@ -758,6 +762,8 @@ int gw_read_client_event(DCB* dcb) { protocol->state = MYSQL_IDLE; } } + /** Free buffer */ + queue = gwbuf_consume(queue, len); goto return_rc; } /* MYSQL_IDLE */ break; diff --git a/server/modules/protocol/mysql_common.c b/server/modules/protocol/mysql_common.c index a1e602083..d6cd5ee12 100644 --- a/server/modules/protocol/mysql_common.c +++ b/server/modules/protocol/mysql_common.c @@ -805,6 +805,7 @@ mysql_send_custom_error (DCB *dcb, int packet_number, int in_affected_rows, cons // writing data in the Client buffer queue dcb->func.write(dcb, buf); + gwbuf_free(buf); return sizeof(mysql_packet_header) + mysql_payload_size; }