Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 109785 - net-snmp memory leak with lm_sensors patch
Summary: net-snmp memory leak with lm_sensors patch
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Server (show other bugs)
Hardware: x86 Linux
: High major (vote)
Assignee: Netmon Herd
: 121031 (view as bug list)
Depends on:
Reported: 2005-10-19 02:59 UTC by Ronan Mullally
Modified: 2006-05-17 09:37 UTC (History)
3 users (show)

See Also:
Package list:
Runtime testing required: ---

valgrind.log (valgrind.log,5.71 KB, text/plain)
2006-01-12 16:07 UTC, Marcelo Goes (RETIRED)
fix memory leaks in hr_sensor.c (net-snmp-lm_sensors-memleak.patch,1.45 KB, patch)
2006-04-17 11:25 UTC, Alex
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ronan Mullally 2005-10-19 02:59:32 UTC
There appears to be a memory leak in net-snmp ( with +lm_sensors.

I've verified lm_sensors is the culprit by re-compiling net-snmp with it
disabled.  With the patch enabled the memory footprint for the snmpd process
grows - I've seen it reach 50MB after a couple of weeks (being queried every 5
minutes).  With the patch disabled net-snmp remains a fairly constant 9MB.

Reproducible: Always
Steps to Reproduce:
1. Install net-snmp with +lm_sensors
2. Start net-snmp, note memory usage
3. Query it every 5 minutes
4. Note memory usage a week later

Actual Results:  
net-snmp memory footprint grows

Portage (hardened/x86/2.6, gcc-3.4.3, glibc-2.3.5-r2,
2.6.11-hardened-r15 i686)
System uname: 2.6.11-hardened-r15 i686 Intel(R) Xeon(TM) CPU 2.80GHz
Gentoo Base System version 1.6.13
dev-lang/python:     2.3.5-r2, 2.4.2
sys-apps/sandbox:    1.2.12
sys-devel/autoconf:  2.13, 2.59-r6
sys-devel/automake:  1.4_p6, 1.5, 1.6.3, 1.7.9-r1, 1.8.5-r3, 1.9.6-r1
sys-devel/libtool:   1.5.20
virtual/os-headers:  2.6.11-r2
CFLAGS="-O2 -march=pentium4 -mfpmath=sse -fomit-frame-pointer -pipe"
CONFIG_PROTECT="/etc /usr/kde/2/share/config /usr/kde/3/share/config
/usr/share/config /var/bind /var/qmail/control"
CONFIG_PROTECT_MASK="/etc/gconf /etc/terminfo /etc/env.d"
CXXFLAGS="-O2 -march=pentium4 -mfpmath=sse -fomit-frame-pointer -pipe"
FEATURES="autoconfig distlocks sandbox sfperms strict"
USE="acl acpi apache2 berkdb bzlib caps crypt dlloader gd gdbm gnutls hardened
ipv6 jpeg libwww lm_sensors minimal mysql mysqli ncurses netboot nls nocardbus
nptl pam pcre perl pic pie png readline sasl session shared sharedmem snmp sse
ssl tcpd threads userlocales x86 zlib userland_GNU kernel_linux elibc_glibc"

net-analyzer/net-snmp           -minimal -perl -ipv6
Comment 1 Andreas Mixich 2005-10-28 13:28:05 UTC
(In reply to comment #0)
I do have the same issues. It is sufficient to issue several requests to the
snmpd per second over the span of a few hours to have snmpd consume more than 100MB.
Comment 2 Marcelo Goes (RETIRED) gentoo-dev 2006-01-12 16:07:53 UTC
Created attachment 76955 [details]

Indeed, there is a memory leak related to the patch.

Tested with:
valgrind --leak-check=yes /usr/sbin/snmpd &> valgrind.log
Comment 3 Marcelo Goes (RETIRED) gentoo-dev 2006-01-22 17:30:08 UTC
I had a look at Fedora's rawhide (the patch came originally from RedHat), and it seems this patch is gone from their sources altogether.
I do not have the Valgrind expertise to fix this problem.

I commented the parts of the ebuilds related to the patch so that people who really want it can simply comment it out. I am not doing a revision bump because the lm_sensors USE flag is off by default and net-snmp is a lengthy compile.

netmon: if you feel differently, please revbump and 5.2.2-r1.

I'm marking this as WONTFIX. If anyone believes himself to be able to fix this problem, please reopen the bug and attach a patch.
Comment 4 Jakub Moc (RETIRED) gentoo-dev 2006-01-31 03:37:46 UTC
*** Bug 121031 has been marked as a duplicate of this bug. ***
Comment 5 Daniel Willmann 2006-01-31 18:46:03 UTC
There is no need to disable the lm_sensors useflag completely since net-snmp already has support for it builtin.
Just uncomment
use lm_sensors && mibs="${mibs} ucd-snmp/lmSensors"
in src_compile (and the DEPEND one) and remerge net-snmp with lm_sensors useflag enabled.
I'm running a
while (true); do snmpwalk -v 2c -c public localhost >/dev/null; done
right now and there's no change in memory consumption (as shown in top) so I'm assuming that the memory leak is in the patch.

I'm wondering if we even need that patch since the output looks fine form what I can tell.
Comment 6 Marcelo Goes (RETIRED) gentoo-dev 2006-02-04 10:10:31 UTC
Thanks Daniel, your suggestion is in cvs.
Comment 7 Alex 2006-04-17 11:25:46 UTC
Created attachment 84849 [details, diff]
fix memory leaks in hr_sensor.c

apply after original net-snmp-lm_sensors.patch
Comment 8 Torbjörn Svensson 2006-05-17 09:37:43 UTC
I would change this row:
strncpy(string, sensor->name, strlen(sensor->name));
strncpy(string, sensor->name, sizeof(string));
as it may lead to an buffer overflow if sensor->name is longer than string. I may be wrong as I am no C programmer, but that's my 2 cents =)