Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak in Print::printf() #2201

Closed
kjcolley7 opened this issue Dec 16, 2018 · 0 comments
Closed

Memory leak in Print::printf() #2201

kjcolley7 opened this issue Dec 16, 2018 · 0 comments

Comments

@kjcolley7
Copy link

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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant