gala-gopher/fix-stackprobe-memory-allocation-and-deallocation-er.patch
Zhen Chen 4a36a5936f sync bugfix patches from openeuler/gala-gopher
- fix ksliprobe get invalid args occasionally at startup
- fix error print when starting gala-gopher
- add system_uuid field to distinguish client when post to pyroscope server
- repair stackprobe caused cpu rush
- add support to pyroscope
- bugfix: add check if thread is 0
- fix stackprobe memory allocation and deallocation errors
- normalize time format in flamegraph svg filename

(cherry picked from commit 6aef5cc8e4e2a34324c3f01663d2b61c0462f4ac)
2023-01-17 22:29:44 +08:00

57 lines
2.0 KiB
Diff

From 01f2d382131f26ca81b0997532d0b73515ca33c7 Mon Sep 17 00:00:00 2001
From: wo_cow <niuqianqian@huawei.com>
Date: Wed, 14 Dec 2022 16:32:13 +0800
Subject: [PATCH] fix stackprobe memory allocation and deallocation errors.
---
.../extends/ebpf.probe/src/stackprobe/stackprobe.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/src/probes/extends/ebpf.probe/src/stackprobe/stackprobe.c b/src/probes/extends/ebpf.probe/src/stackprobe/stackprobe.c
index da09094..fa37a72 100644
--- a/src/probes/extends/ebpf.probe/src/stackprobe/stackprobe.c
+++ b/src/probes/extends/ebpf.probe/src/stackprobe/stackprobe.c
@@ -105,7 +105,7 @@ typedef struct {
struct bpf_link_hash_value {
enum pid_state_t pid_state;
char elf_path[MAX_PATH_LEN];
- struct bpf_link *bpf_links[32];
+ struct bpf_link *bpf_links[32]; // 32 cover num of probes in memleak.bpf.c
};
struct bpf_link_hash_t {
@@ -314,7 +314,7 @@ static struct raw_stack_trace_s *create_raw_stack_trace(struct stack_trace_s *st
size_t stack_size = st->cpus_num * PERCPU_SAMPLE_COUNT;
size_t mem_size = sizeof(struct raw_stack_trace_s);
- mem_size += (stack_size * sizeof(struct stack_id_s));
+ mem_size += (stack_size * sizeof(struct raw_trace_s));
raw_stack_trace = (struct raw_stack_trace_s *)malloc(mem_size);
if (!raw_stack_trace) {
@@ -747,7 +747,6 @@ static void destroy_svg_stack_trace(struct svg_stack_trace_s **ptr_svg_st)
static void destroy_stack_trace(struct stack_trace_s **ptr_st)
{
- // TODO:destroy_svg_stack_trace?
struct stack_trace_s *st = *ptr_st;
*ptr_st = NULL;
if (!st) {
@@ -761,6 +760,13 @@ static void destroy_stack_trace(struct stack_trace_s **ptr_st)
}
}
+ for (int i = 0; i < STACK_SVG_MAX; i++) {
+ if (st->svg_stack_traces[i] == NULL) {
+ continue;
+ }
+ destroy_svg_stack_trace(&st->svg_stack_traces[i]);
+ }
+
if (st->ksymbs) {
destroy_ksymbs_tbl(st->ksymbs);
(void)free(st->ksymbs);
--
2.33.0