From 908d040191208bd893c1685e0cd7e41937cb8f63 Mon Sep 17 00:00:00 2001 From: echodo <2220386943@qq.com> Date: Mon, 23 Jun 2025 17:14:24 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=96=E7=A0=81=E9=97=AE=E9=A2=98=E4=BF=AE?= =?UTF-8?q?=E6=94=B9,=E6=8C=87=E9=92=88=E5=88=A0=E9=99=A4=E5=90=8E?= =?UTF-8?q?=E6=9C=AA=E8=AE=BE=E7=BD=AE=E6=88=90nullptr,=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pmu/sampler.cpp | 9 ++++++--- pmu/sampler.h | 2 +- pmu/spe.cpp | 9 +++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/pmu/sampler.cpp b/pmu/sampler.cpp index aa23978..cb78a80 100644 --- a/pmu/sampler.cpp +++ b/pmu/sampler.cpp @@ -129,7 +129,7 @@ int KUNPENG_PMU::PerfSampler::Close() return SUCCESS; } -void KUNPENG_PMU::PerfSampler::UpdatePidInfo(const pid_t &pid, const int &tid) +void KUNPENG_PMU::PerfSampler::UpdatePidInfo(const int &tid) { auto findProc = procMap.find(tid); if (findProc == procMap.end()) { @@ -149,6 +149,9 @@ void KUNPENG_PMU::PerfSampler::UpdateCommInfo(KUNPENG_PMU::PerfEvent *event) procTopo->tid = event->comm.tid; procTopo->pid = event->comm.pid; procTopo->comm = static_cast(malloc(strlen(event->comm.comm) + 1)); + if (procTopo->comm == nullptr) { + return; + } strcpy(procTopo->comm, event->comm.comm); DBG_PRINT("Add to proc map: %d\n", event->comm.tid); procMap[event->comm.tid] = procTopo; @@ -283,7 +286,7 @@ void KUNPENG_PMU::PerfSampler::ReadRingBuffer(vector &data, vectorfork.pid, event->fork.tid); - UpdatePidInfo(event->fork.pid, event->fork.tid); + UpdatePidInfo(event->fork.tid); break; } case PERF_RECORD_COMM: { @@ -310,7 +313,7 @@ void KUNPENG_PMU::PerfSampler::FillComm(const size_t &start, const size_t &end, auto& pmuData = data[i]; auto findProc = procMap.find(pmuData.tid); if (findProc == procMap.end()) { - UpdatePidInfo(pmuData.pid, pmuData.tid); + UpdatePidInfo(pmuData.tid); findProc = procMap.find(pmuData.tid); if (findProc == procMap.end()) { continue; diff --git a/pmu/sampler.h b/pmu/sampler.h index 41fcdff..6c49a74 100644 --- a/pmu/sampler.h +++ b/pmu/sampler.h @@ -59,7 +59,7 @@ namespace KUNPENG_PMU { void ReadRingBuffer(std::vector &data, std::vector &sampleIps, std::vector &extPool, std::vector &switchData); void FillComm(const size_t &start, const size_t &end, std::vector &data); - void UpdatePidInfo(const pid_t &pid, const int &tid); + void UpdatePidInfo(const int &tid); void UpdateCommInfo(KUNPENG_PMU::PerfEvent *event); void ParseSwitch(KUNPENG_PMU::PerfEvent *event, struct PmuSwitchData *switchCurData); void ParseBranchSampleData(struct PmuData *pmuData, PerfRawSample *sample, union PerfEvent *event, std::vector &extPool); diff --git a/pmu/spe.cpp b/pmu/spe.cpp index 2bc42c4..d87587b 100644 --- a/pmu/spe.cpp +++ b/pmu/spe.cpp @@ -132,14 +132,17 @@ static void CoreSpeClose(struct SpeCoreContext *ctx, struct SpeContext *speCtx) { if (ctx->speMpage && ctx->speMpage != MAP_FAILED) { munmap(ctx->speMpage, speCtx->speMmapSize); + ctx->speMpage = nullptr; } if (ctx->auxMpage && ctx->auxMpage != MAP_FAILED) { munmap(ctx->auxMpage, speCtx->auxMmapSize); + ctx->auxMpage = nullptr; } if (ctx->dummyMpage && ctx->dummyMpage != MAP_FAILED) { munmap(ctx->dummyMpage, speCtx->dummyMmapSize); + ctx->dummyMpage = nullptr; } if (ctx->speFd > 0) { @@ -211,6 +214,7 @@ int SpeOpen(PmuEvt *attr, int cpu, SpeContext *ctx) if (attr->type == -1) { free(ctx); + ctx = nullptr; return LIBPERF_ERR_SPE_UNAVAIL; } @@ -225,6 +229,7 @@ int SpeOpen(PmuEvt *attr, int cpu, SpeContext *ctx) ctx->coreCtxes = (struct SpeCoreContext *)malloc(sizeof(struct SpeCoreContext)); if (!ctx->coreCtxes) { free(ctx); + ctx = nullptr; return COMMON_ERR_NOMEM; } ctx->coreCtxes->mask = ctx->auxMmapSize - 1; @@ -233,7 +238,9 @@ int SpeOpen(PmuEvt *attr, int cpu, SpeContext *ctx) auto err = CoreSpeOpen(&ctx->coreCtxes, ctx, attr, cpu); if (err != 0) { free(ctx->coreCtxes); + ctx->coreCtxes = nullptr; free(ctx); + ctx = nullptr; return err; } return SUCCESS; @@ -304,7 +311,9 @@ void SpeClose(struct SpeContext *ctx) } free(ctx->coreCtxes); + ctx->coreCtxes = nullptr; free(ctx); + ctx = nullptr; return; } -- Gitee