Skip to content

Memory leak in Print::printf() #2201

Closed
Closed
@kjcolley7

Description

@kjcolley7

Permalink to impacted code region:

if(len > 64){

In the code for Print::printf(), when printing text that would result in a length that would exceed the size of the local buffer (>= 64), a new buffer will be heap-allocated. However, the check at the end of the function is not correct. When the number of characters that would be printed is exactly 64, then a buffer of 65 bytes will be allocated. However, the check at the end will fail (as len will be 64 which is not greater than 64), causing this buffer to be leaked.

I'd recommend changing this check to be as follows:

if(temp != loc_buf) {
    delete[] temp;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions