Resolve a couple of recent memory leaks in pcp-htop

Makes the pcp-htop binary valgrind-clean once more.
This commit is contained in:
Nathan Scott 2021-06-10 11:25:31 +10:00 committed by BenBE
parent df752dd189
commit 0bd1025e94
1 changed files with 6 additions and 0 deletions

View File

@ -370,6 +370,10 @@ void Metric_enableThreads(void) {
} }
bool Metric_fetch(struct timeval *timestamp) { bool Metric_fetch(struct timeval *timestamp) {
if (pcp->result) {
pmFreeResult(pcp->result);
pcp->result = NULL;
}
int sts = pmFetch(pcp->total, pcp->fetch, &pcp->result); int sts = pmFetch(pcp->total, pcp->fetch, &pcp->result);
if (sts < 0) { if (sts < 0) {
if (pmDebugOptions.appl0) if (pmDebugOptions.appl0)
@ -502,6 +506,8 @@ void Platform_init(void) {
void Platform_done(void) { void Platform_done(void) {
pmDestroyContext(pcp->context); pmDestroyContext(pcp->context);
pmFreeResult(pcp->result);
free(pcp->release);
free(pcp->fetch); free(pcp->fetch);
free(pcp->pmids); free(pcp->pmids);
free(pcp->names); free(pcp->names);