Skip to content

Commit 35c1055

Browse files
committed
remove callback-string
1 parent c545f09 commit 35c1055

File tree

3 files changed

+16
-24
lines changed

3 files changed

+16
-24
lines changed

callstack.c

+10-18
Original file line numberDiff line numberDiff line change
@@ -49,45 +49,36 @@ struct callstack_s *callstack_current(void)
4949
return cs;
5050
}
5151

52-
const char *callstack_string(struct callstack_s *cs)
52+
void callstack_print(struct callstack_s *cs)
5353
{
54-
if (cs->string != NULL) {
55-
return cs->string;
56-
}
57-
58-
char buffer[10000], *p = buffer;
5954
int offset, lineno, i;
6055
for (i = 0; i < cs->ip_num; i++) {
6156
uintptr_t address = cs->ips[i];
6257
if (address == 0) {
6358
break;
6459
}
6560

66-
p += sprintf(p, " 0x%016lx", address);
61+
printf(" 0x%016lx", address);
6762

68-
p += sprintf(p, " %s", addr_maps_search(address));
63+
printf(" %s", addr_maps_search(address));
6964

7065
const char *proc_name = symtab_by_address(address, &offset);
7166
if (proc_name != NULL) {
72-
p += sprintf(p, " %s()+%d", proc_name, offset);
67+
printf(" %s()+%d", proc_name, offset);
7368
}
7469

7570
/* @address is return-address, so address-1 is calling-line */
7671
const char *file_name = debug_line_search(address - 1, &lineno);
7772
if (file_name != NULL) {
78-
p += sprintf(p, " %s:%d", file_name, lineno);
73+
printf(" %s:%d", file_name, lineno);
7974
}
8075

81-
p += sprintf(p, "\n");
76+
printf("\n");
8277

8378
if (proc_name && strcmp(proc_name, "main") == 0) {
8479
break;
8580
}
8681
}
87-
88-
cs->string = malloc(p - buffer + 1);
89-
memcpy(cs->string, buffer, p - buffer + 1);
90-
return cs->string;
9182
}
9283

9384
static int callstack_cmp(const void *a, const void *b)
@@ -119,7 +110,7 @@ void callstack_report(void)
119110
" expired=%d (%d bytes), free_expired=%d (%d bytes)\n"
120111
" alloc=%d (%d bytes), free=%d (%d bytes)\n"
121112
" freed memory live time: min=%d max=%d average=%d\n"
122-
" un-freed memory live time: max=%d\n%s\n",
113+
" un-freed memory live time: max=%d\n",
123114
cs->id,
124115
cs->expired_count - cs->free_expired_count,
125116
cs->expired_size - cs->free_expired_size,
@@ -129,7 +120,8 @@ void callstack_report(void)
129120
cs->free_count, cs->free_size,
130121
cs->free_min, cs->free_max,
131122
cs->free_count ? cs->free_total / cs->free_count : 0,
132-
cs->unfree_max,
133-
callstack_string(cs));
123+
cs->unfree_max);
124+
callstack_print(cs);
125+
printf("\n");
134126
}
135127
}

callstack.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ struct callstack_s {
2020
int unfree_max;
2121

2222
int id;
23-
char *string;
2423
};
2524

2625
struct callstack_s *callstack_current(void);
27-
const char *callstack_string(struct callstack_s *cs);
26+
void callstack_print(struct callstack_s *cs);
2827
void callstack_report(void);
2928

3029
#endif

memblock.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ static LIST_HEAD(g_memblock_expire);
3232
int memblock_new(uintptr_t pointer, size_t size)
3333
{
3434
if (pointer == 0) {
35-
printf("Warning: alloc returns NULL at\n%s",
36-
callstack_string(callstack_current()));
35+
printf("Warning: alloc returns NULL at\n");
36+
callstack_print(callstack_current());
3737
return 0;
3838
}
3939

@@ -126,8 +126,9 @@ static void memblock_expire_one(struct memblock_s *mb)
126126
static int callstack_id = 1;
127127
if (cs->id == 0) { /* first time */
128128
cs->id = callstack_id++;
129-
printf("CallStack[%d]: memory expires with %ld bytes, backtrace:\n%s",
130-
cs->id, mb->size, callstack_string(cs));
129+
printf("CallStack[%d]: memory expires with %ld bytes, backtrace:\n",
130+
cs->id, mb->size);
131+
callstack_print(cs);
131132
} else if (cs->free_expired_count < DONOT_SHOW_AFTER_FREE_EXPIRES) {
132133
printf("CallStack[%d]: memory expires with %ld bytes, %d times again\n",
133134
cs->id, mb->size, cs->expired_count);

0 commit comments

Comments
 (0)