Added check routine for gw_buffer. Only effective in debug build.

This commit is contained in:
vraatikka 2013-09-17 15:10:16 +03:00
parent 5fba84a4ee
commit 4cf5b3293f
2 changed files with 15 additions and 8 deletions

View File

@ -37,7 +37,7 @@
#include <stdlib.h>
#include <buffer.h>
#include <atomic.h>
#include <skygw_debug.h>
/**
* Allocate a new gateway buffer structure of size bytes.
@ -82,7 +82,7 @@ SHARED_BUF *sbuf;
rval->sbuf = sbuf;
rval->next = NULL;
rval->command = 0;
CHK_GWBUF(rval);
return rval;
}
@ -95,9 +95,10 @@ void
gwbuf_free(GWBUF *buf)
{
atomic_add(&buf->sbuf->refcount, -1);
CHK_GWBUF(buf);
if (buf->sbuf->refcount == 0)
{
free(buf->sbuf->data);
free(buf->sbuf->data);
free(buf->sbuf);
}
free(buf);
@ -129,7 +130,7 @@ GWBUF *rval;
rval->end = buf->end;
rval->next = NULL;
rval->command = buf->command;
CHK_GWBUF(rval);
return rval;
}
/**
@ -146,9 +147,10 @@ GWBUF *
gwbuf_append(GWBUF *head, GWBUF *tail)
{
GWBUF *ptr = head;
if (!head)
return tail;
CHK_GWBUF(head);
while (ptr->next)
{
ptr = ptr->next;
@ -177,7 +179,7 @@ GWBUF *
gwbuf_consume(GWBUF *head, unsigned int length)
{
GWBUF *rval = head;
CHK_GWBUF(head);
GWBUF_CONSUME(head, length);
if (GWBUF_EMPTY(head))
{
@ -197,7 +199,7 @@ unsigned int
gwbuf_length(GWBUF *head)
{
int rval = 0;
CHK_GWBUF(head);
while (head)
{
rval += GWBUF_LENGTH(head);

View File

@ -16,7 +16,7 @@
* Copyright SkySQL Ab 2013
*/
#include <stdio.h>
#include <assert.h>
#define __USE_UNIX98 1
@ -360,6 +360,11 @@ typedef enum skygw_chk_t {
"Session under- or overflow"); \
}
#define CHK_GWBUF(b) { \
ss_info_dassert(((b)->start <= (b)->end), \
"gwbuf start has passed the endpoint"); \
}
#if defined(SS_DEBUG)
bool conn_open[1024];
#endif