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

Already on GitHub? Sign in to your account

libpcp_pmda: Fixed a memory leak detected by valgrind. #21

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants

Original issue created at: #19

pmdaproc has memory leaks using the following python monitor client to collect process list at 1 second interval.

/proc/pmdaproc_pid/smaps: (Heap size hits 18Mb after 5 days run)
02416000-035a1000 rw-p 00000000 00:00 0 [heap]
Size: 17964 kB
Rss: 17852 kB
Pss: 17852 kB
Shared_Clean: 0 kB
Shared_Dirty: 0 kB
Private_Clean: 0 kB
Private_Dirty: 17852 kB
Referenced: 17852 kB
Anonymous: 17852 kB
AnonHugePages: 0 kB
Swap: 0 kB
KernelPageSize: 4 kB
MMUPageSize: 4 kB
Locked: 0 kB
VmFlags: rd wr mr mw me ac

Valgrind output:

0x42
1
Leak_DefinitelyLost

615,463 bytes in 25,293 blocks are definitely lost in loss record 65 of 65
615463
25293



0x4C2741D
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so
malloc


0x505C48D
/usr/local/lib/libpcp.so.3
__pmDecodeNameList

/home/ec2-user/pcp/src/libpcp/src
p_pmns.c
344


0x4E38277
/usr/lib64/libpcp_pmda.so.3
__pmdaMainPDU
/home/ec2-user/pcp/src/libpcp_pmda/src
mainloop.c
201


0x4E386D7
/usr/lib64/libpcp_pmda.so.3
pmdaMain
/home/ec2-user/pcp/src/libpcp_pmda/src
mainloop.c
428


0x402CA6
/var/lib/pcp/pmdas/proc/pmdaproc
main
/home/ec2-user/pcp/src/pmdas/linux_proc
pmda.c
3153


Python client used to repro the issue:

!/usr/bin/python

from cpmapi import PM_TYPE_U32, PM_TYPE_FLOAT, PM_TYPE_STRING, PM_TYPE_U64
from pcp import pmapi

import json
import sys
import time

class Prototype(object):

def __init__(self):
    self.context = None
    self.opts = pmapi.pmOptions()
    self.opts.pmSetShortOptions("V?")
    self.opts.pmSetLongOptionHeader("Options")
    self.opts.pmSetLongOptionVersion()
    self.opts.pmSetLongOptionHelp()

def execute(self):
    metrics = ('proc.psinfo.pid', 'proc.psinfo.cmd', 'proc.psinfo.nice')
    pmids = self.context.pmLookupName(metrics)
    descs = self.context.pmLookupDescs(pmids)
    result = self.context.pmFetch(pmids)
    process_list = []
    for inst in range(result.contents.get_numval(0)):
        pid_value = self.context.pmExtractValue(
                    result.contents.get_valfmt(0),
                    result.contents.get_vlist(0, inst),
                    descs[0].contents.type, descs[0].contents.type)
        pid =  pid_value.ull
        process_list.append(pid)

    self.context.pmFreeResult(result)
    print json.dumps(process_list)

def connect(self):
    self.context = pmapi.pmContext.fromOptions(self.opts, sys.argv)

if name == 'main':
testApp = Prototype()
testApp.connect()
while True:
testApp.execute()
time.sleep(1)

Contributor

natoscott commented May 25, 2015

Ken reviewed this, added automated testing, and merged it - closing.

@natoscott natoscott closed this May 25, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment