MXS-1740 Hintfilter leaks memory
Single spot where an existing hint ptr was overwritten. Removed gwbuf_add_hint() because it was adding hints at the opposite end compared to functions in hint.h. Added hint_splice() to replace.
This commit is contained in:
@ -379,15 +379,6 @@ extern char *gwbuf_get_property(GWBUF *buf, char *name);
|
|||||||
*/
|
*/
|
||||||
extern GWBUF *gwbuf_make_contiguous(GWBUF *buf);
|
extern GWBUF *gwbuf_make_contiguous(GWBUF *buf);
|
||||||
|
|
||||||
/**
|
|
||||||
* Add hint to a buffer.
|
|
||||||
*
|
|
||||||
* @param buf The buffer to add the hint to
|
|
||||||
* @param hint The hint. Note that the ownership of @c hint is transferred
|
|
||||||
* to @c buf.
|
|
||||||
*/
|
|
||||||
extern void gwbuf_add_hint(GWBUF *buf, HINT *hint);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a buffer object to GWBUF buffer.
|
* Add a buffer object to GWBUF buffer.
|
||||||
*
|
*
|
||||||
|
@ -53,6 +53,7 @@ typedef struct hint
|
|||||||
HINT *hint_alloc(HINT_TYPE, void *, unsigned int);
|
HINT *hint_alloc(HINT_TYPE, void *, unsigned int);
|
||||||
HINT *hint_create_parameter(HINT *, char *, const char *);
|
HINT *hint_create_parameter(HINT *, char *, const char *);
|
||||||
HINT *hint_create_route(HINT *, HINT_TYPE, const char *);
|
HINT *hint_create_route(HINT *, HINT_TYPE, const char *);
|
||||||
|
HINT *hint_splice(HINT *head, HINT *list);
|
||||||
void hint_free(HINT *);
|
void hint_free(HINT *);
|
||||||
HINT *hint_dup(const HINT *);
|
HINT *hint_dup(const HINT *);
|
||||||
bool hint_exists(HINT **, HINT_TYPE);
|
bool hint_exists(HINT **, HINT_TYPE);
|
||||||
|
@ -814,28 +814,6 @@ gwbuf_make_contiguous(GWBUF *orig)
|
|||||||
return newbuf;
|
return newbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
gwbuf_add_hint(GWBUF *buf, HINT *hint)
|
|
||||||
{
|
|
||||||
HINT *ptr;
|
|
||||||
|
|
||||||
spinlock_acquire(&buf->gwbuf_lock);
|
|
||||||
if (buf->hint)
|
|
||||||
{
|
|
||||||
ptr = buf->hint;
|
|
||||||
while (ptr->next)
|
|
||||||
{
|
|
||||||
ptr = ptr->next;
|
|
||||||
}
|
|
||||||
ptr->next = hint;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
buf->hint = hint;
|
|
||||||
}
|
|
||||||
spinlock_release(&buf->gwbuf_lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t gwbuf_copy_data(const GWBUF *buffer, size_t offset, size_t bytes, uint8_t* dest)
|
size_t gwbuf_copy_data(const GWBUF *buffer, size_t offset, size_t bytes, uint8_t* dest)
|
||||||
{
|
{
|
||||||
uint32_t buflen;
|
uint32_t buflen;
|
||||||
|
@ -113,6 +113,32 @@ hint_create_route(HINT *head, HINT_TYPE type, const char *data)
|
|||||||
return hint;
|
return hint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Insert a hint list before head.
|
||||||
|
*
|
||||||
|
* @param head Element before which contents is inserted.
|
||||||
|
* May be NULL, in which case the result is list.
|
||||||
|
* @param list Hint list to prepend
|
||||||
|
* @return Head of list
|
||||||
|
*/
|
||||||
|
HINT *
|
||||||
|
hint_splice(HINT *head, HINT *list)
|
||||||
|
{
|
||||||
|
ss_dassert(list);
|
||||||
|
if (head)
|
||||||
|
{
|
||||||
|
HINT* tail = list;
|
||||||
|
while (tail->next)
|
||||||
|
{
|
||||||
|
tail = tail->next;
|
||||||
|
}
|
||||||
|
tail->next = head;
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create name/value parameter hint
|
* Create name/value parameter hint
|
||||||
*
|
*
|
||||||
|
@ -467,10 +467,6 @@ test1()
|
|||||||
ss_info_dassert(size == buflen, "Incorrect buffer size");
|
ss_info_dassert(size == buflen, "Incorrect buffer size");
|
||||||
ss_info_dassert(0 == GWBUF_EMPTY(buffer), "Buffer should not be empty");
|
ss_info_dassert(0 == GWBUF_EMPTY(buffer), "Buffer should not be empty");
|
||||||
ss_info_dassert(GWBUF_IS_TYPE_UNDEFINED(buffer), "Buffer type should be undefined");
|
ss_info_dassert(GWBUF_IS_TYPE_UNDEFINED(buffer), "Buffer type should be undefined");
|
||||||
ss_dfprintf(stderr, "\t..done\nSet a hint for the buffer");
|
|
||||||
hint = hint_create_parameter(NULL, (char*)"name", (char*)"value");
|
|
||||||
gwbuf_add_hint(buffer, hint);
|
|
||||||
ss_info_dassert(hint == buffer->hint, "Buffer should point to first and only hint");
|
|
||||||
ss_dfprintf(stderr, "\t..done\nSet a property for the buffer");
|
ss_dfprintf(stderr, "\t..done\nSet a property for the buffer");
|
||||||
gwbuf_add_property(buffer, (char*)"name", (char*)"value");
|
gwbuf_add_property(buffer, (char*)"name", (char*)"value");
|
||||||
ss_info_dassert(0 == strcmp("value", gwbuf_get_property(buffer, (char*)"name")),
|
ss_info_dassert(0 == strcmp("value", gwbuf_get_property(buffer, (char*)"name")),
|
||||||
|
@ -208,8 +208,11 @@ routeQuery(MXS_FILTER *instance, MXS_FILTER_SESSION *session, GWBUF *queue)
|
|||||||
{
|
{
|
||||||
my_session->request = NULL;
|
my_session->request = NULL;
|
||||||
my_session->query_len = 0;
|
my_session->query_len = 0;
|
||||||
HINT *hint = hint_parser(my_session, queue);
|
HINT *new_hint = hint_parser(my_session, queue);
|
||||||
queue->hint = hint;
|
if (new_hint)
|
||||||
|
{
|
||||||
|
queue->hint = hint_splice(queue->hint, new_hint);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now process the request */
|
/* Now process the request */
|
||||||
|
Reference in New Issue
Block a user