There appears to be a memory leak in net-snmp (5.2.1.2-r1) 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 2.0.51.22-r3 (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/binutils: 2.15.92.0.2-r10 sys-devel/libtool: 1.5.20 virtual/os-headers: 2.6.11-r2 ACCEPT_KEYWORDS="x86" AUTOCLEAN="yes" CBUILD="i686-pc-linux-gnu" CFLAGS="-O2 -march=pentium4 -mfpmath=sse -fomit-frame-pointer -pipe" CHOST="i686-pc-linux-gnu" 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" DISTDIR="/var/lib/portage/distfiles" FEATURES="autoconfig distlocks sandbox sfperms strict" GENTOO_MIRRORS=" http://gentoo.blueyonder.co.uk/ ftp://ftp.mirror.ac.uk/sites/distro.ibiblio.org/pub/linux/distributions/gentoo/ ftp://ftp.belnet.be/mirrors/rsync.gentoo.org/gentoo ftp://ftp.easynet.nl/mirror/gentoo/" MAKEOPTS="-j4" PKGDIR="/usr/portage//packages/x86/" PORTAGE_TMPDIR="/var/tmp" PORTDIR="/usr/portage/" PORTDIR_OVERLAY="/usr/local/portage" SYNC="rsync://rsync.europe.gentoo.org/gentoo-portage" 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" Unset: ASFLAGS, CTARGET, LANG, LC_ALL, LDFLAGS, LINGUAS /etc/portage/package.use: net-analyzer/net-snmp -minimal -perl -ipv6
(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.
Created attachment 76955 [details] valgrind.log Indeed, there is a memory leak related to the patch. Tested with: valgrind --leak-check=yes /usr/sbin/snmpd &> valgrind.log
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 5.2.1.2-r1 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.
*** Bug 121031 has been marked as a duplicate of this bug. ***
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.
Thanks Daniel, your suggestion is in cvs.
Created attachment 84849 [details, diff] fix memory leaks in hr_sensor.c apply after original net-snmp-lm_sensors.patch
I would change this row: strncpy(string, sensor->name, strlen(sensor->name)); to: 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 =)