diff --git a/pmu/sampler.cpp b/pmu/sampler.cpp index aa23978a4446baa5de92b87f6133393ca2ba11dd..cb78a80f1e896f4d64f972ddf0b08dd0f9834f57 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 41fcdff17aa7b90cb1c911ce56e04950bbb4f2c2..6c49a74d6e594aec3cb18bd3087743c087e9b088 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 2bc42c400bb7ba277a6da589d52262e2d5f06ea8..d87587b7bac322cb57669ce45eac5ae384515f62 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; }