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

Handle a memory leak when contextName is used in the PDU. The memory … #78

Closed
wants to merge 1 commit into from

Conversation

jain-mukesh
Copy link

We found that the internalPDU->contextName was assigned to the internalPDU->community resulting in losing the reference to the assigned memory of internalPDU->contextName. This memory is never free'ed when the internalPDU is deallocated. I tested the issue in 5.3, 5.8 and master branch. The issue does not happen if contextName is not used

Proposed fix:
contextNames memory should be freed before assignment to community, so that the memory is not lost.

This is discussed further in issue #58 along with a valgrind report.

…for contextName is assigned to community and is hence lost.

This is discussed further in issue net-snmp#58 along with a valgrind report.
bvanassche pushed a commit to bvanassche/net-snmp that referenced this pull request Mar 9, 2020
Fix a memory leak when contextName is used in the PDU. The memory for
contextName is assigned to community and is hence lost. This patch
fixes the following Valgrind complaint:

at 0x4C29EA3: malloc (vg_replace_malloc.c:309)
by 0x653F294: snmp_clone_mem (in /usr/lib64/libnetsnmp.so.31.0.2)
by 0x653F3E7: ??? (in /usr/lib64/libnetsnmp.so.31.0.2)
by 0x653F90D: snmp_clone_pdu (in /usr/lib64/libnetsnmp.so.31.0.2)
by 0x60E3837: handle_agentx_packet (in /usr/lib64/libnetsnmpagent.so.31.0.2)
by 0x6567ED0: ??? (in /usr/lib64/libnetsnmp.so.31.0.2)
by 0x6568F40: _sess_read (in /usr/lib64/libnetsnmp.so.31.0.2)
by 0x65698A8: snmp_sess_read2 (in /usr/lib64/libnetsnmp.so.31.0.2)
by 0x65698FA: snmp_read2 (in /usr/lib64/libnetsnmp.so.31.0.2)
by 0x656993B: snmp_read (in /usr/lib64/libnetsnmp.so.31.0.2)
by 0x60DF30A: agent_check_and_process (in /usr/lib64/libnetsnmpagent.so.31.0.2)

See also net-snmp#78.
See also net-snmp#58.

[ bvanassche: modified commit message and patch ]
@bvanassche
Copy link
Contributor

A slightly modified patch has been applied on the v5.8 and master branches. Thanks for the patch!

@bvanassche bvanassche closed this Mar 9, 2020
LeSpocky pushed a commit to LeSpocky/net-snmp that referenced this pull request Apr 13, 2020
Fix a memory leak when contextName is used in the PDU. The memory for
contextName is assigned to community and is hence lost. This patch
fixes the following Valgrind complaint:

at 0x4C29EA3: malloc (vg_replace_malloc.c:309)
by 0x653F294: snmp_clone_mem (in /usr/lib64/libnetsnmp.so.31.0.2)
by 0x653F3E7: ??? (in /usr/lib64/libnetsnmp.so.31.0.2)
by 0x653F90D: snmp_clone_pdu (in /usr/lib64/libnetsnmp.so.31.0.2)
by 0x60E3837: handle_agentx_packet (in /usr/lib64/libnetsnmpagent.so.31.0.2)
by 0x6567ED0: ??? (in /usr/lib64/libnetsnmp.so.31.0.2)
by 0x6568F40: _sess_read (in /usr/lib64/libnetsnmp.so.31.0.2)
by 0x65698A8: snmp_sess_read2 (in /usr/lib64/libnetsnmp.so.31.0.2)
by 0x65698FA: snmp_read2 (in /usr/lib64/libnetsnmp.so.31.0.2)
by 0x656993B: snmp_read (in /usr/lib64/libnetsnmp.so.31.0.2)
by 0x60DF30A: agent_check_and_process (in /usr/lib64/libnetsnmpagent.so.31.0.2)

See also net-snmp#78.
See also net-snmp#58.

[ bvanassche: modified commit message and patch ]
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

Successfully merging this pull request may close these issues.

None yet

2 participants