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 if realloc() fails #31

Open
l2dy opened this issue May 9, 2024 · 0 comments
Open

Memory leak if realloc() fails #31

l2dy opened this issue May 9, 2024 · 0 comments

Comments

@l2dy
Copy link

l2dy commented May 9, 2024

If realloc() fails, it returns NULL and the original block of memory is left untouched; it is not freed or moved.

In our case, we lost the reference to the original block of memory and it is not freed, causing a memory leak. This happens if there is an error, for example when the host is out of memory.

mini-snmpd/mib.c

Lines 104 to 106 in 45765e3

data->buffer = realloc(data->buffer, data->max_length);
if (!data->buffer)
return 2;

If this happens, it is recommended to free the original block of memory, or keep data->buffer unchanged.

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