[MXS-840] Return value of gwbuf_make_contiguous should be checked. Created: 2016-08-26  Updated: 2017-03-20  Resolved: 2017-03-20

Status: Closed
Project: MariaDB MaxScale
Component/s: N/A
Affects Version/s: None
Fix Version/s: N/A

Type: Bug Priority: Minor
Reporter: Johan Wikman Assignee: Unassigned
Resolution: Incomplete Votes: 0
Labels: None


 Description   

A common pattern is

void function(GWBUF *queue)
{
    ...
    queue = gwbuf_make_contiguous(queue);
}

However, gwbuf_make_contiguous behaves like realloc, that is, the memory allocation can fail and the function can return NULL, in which case the original buffer will leak and the code will steam ahead towards a SIGSEGV.

Correct way would be

void function(GWBUF *queue)
{
    ...
    GWBUF *tmp = gwbuf_make_contiguous(queue);
    if (tmp)
    {
        queue = tmp;
    }
    else
    {
        // Handle problem.
    }
}



 Comments   
Comment by Johan Wikman [ 2017-03-20 ]

A bit too general.

Generated at Thu Feb 08 04:02:19 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.