diff --git a/include/maxscale/buffer.h b/include/maxscale/buffer.h index b5d75dc67..02a208e19 100644 --- a/include/maxscale/buffer.h +++ b/include/maxscale/buffer.h @@ -368,16 +368,13 @@ extern char *gwbuf_get_property(GWBUF *buf, char *name); /** * Convert a chain of GWBUF structures into a single GWBUF structure * - * @param orig The chain to convert + * @param orig The chain to convert, must not be used after the function call * - * @return NULL if @c buf is NULL or if a memory allocation fails, - * @c buf if @c buf already is contiguous, and otherwise - * a contigious copy of @c buf. + * @return A contiguous version of @c buf. * - * @attention If a non-NULL value is returned, the @c buf should no - * longer be used as it may have been freed. + * @attention Never returns NULL, memory allocation failures abort the process */ -extern GWBUF *gwbuf_make_contiguous(GWBUF *buf); +extern GWBUF* gwbuf_make_contiguous(GWBUF *buf); /** * Add a buffer object to GWBUF buffer. diff --git a/server/core/buffer.cc b/server/core/buffer.cc index f870c838d..a938c1f67 100644 --- a/server/core/buffer.cc +++ b/server/core/buffer.cc @@ -786,13 +786,8 @@ gwbuf_get_property(GWBUF *buf, char *name) return NULL; } -GWBUF * -gwbuf_make_contiguous(GWBUF *orig) +GWBUF* gwbuf_make_contiguous(GWBUF *orig) { - GWBUF *newbuf; - uint8_t *ptr; - int len; - if (orig == NULL) { ss_info_dassert(!true, "gwbuf_make_contiguous: NULL buffer"); @@ -803,20 +798,21 @@ gwbuf_make_contiguous(GWBUF *orig) return orig; } - if ((newbuf = gwbuf_alloc(gwbuf_length(orig))) != NULL) - { - newbuf->gwbuf_type = orig->gwbuf_type; - newbuf->hint = hint_dup(orig->hint); - ptr = GWBUF_DATA(newbuf); + GWBUF* newbuf = gwbuf_alloc(gwbuf_length(orig)); + MXS_ABORT_IF_NULL(newbuf); - while (orig) - { - len = GWBUF_LENGTH(orig); - memcpy(ptr, GWBUF_DATA(orig), len); - ptr += len; - orig = gwbuf_consume(orig, len); - } + newbuf->gwbuf_type = orig->gwbuf_type; + newbuf->hint = hint_dup(orig->hint); + uint8_t* ptr = GWBUF_DATA(newbuf); + + while (orig) + { + int len = GWBUF_LENGTH(orig); + memcpy(ptr, GWBUF_DATA(orig), len); + ptr += len; + orig = gwbuf_consume(orig, len); } + return newbuf; }