Skip to content

Commit 39514fb

Browse files
Add get_pnt_start to save the stack space usage
Signed-off-by: Xiang Xiao <[email protected]> Change-Id: I93ee8efa16ff0997dcbc1a8cf5eb1f057d7680ce
1 parent 2830065 commit 39514fb

File tree

1 file changed

+31
-11
lines changed

1 file changed

+31
-11
lines changed

chunk.c

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,30 @@ static int expand_chars(const void *buf, const int buf_size,
776776
return out_p - out;
777777
}
778778

779+
/*
780+
* static void *get_pnt_start
781+
*
782+
* With a slot, return the user start pointer.
783+
*
784+
* ARGUMENTS:
785+
*
786+
* slot_p -> Pointer to a slot structure that we are getting info on.
787+
*/
788+
static void *get_pnt_start(const skip_alloc_t *slot_p)
789+
{
790+
if (BIT_IS_SET(slot_p->sa_flags, ALLOC_FLAG_FENCE)) {
791+
if (BIT_IS_SET(slot_p->sa_flags, ALLOC_FLAG_VALLOC)) {
792+
return (char *)slot_p->sa_mem + BLOCK_SIZE;
793+
}
794+
else {
795+
return (char *)slot_p->sa_mem + FENCE_BOTTOM_SIZE;
796+
}
797+
}
798+
else {
799+
return slot_p->sa_mem;
800+
}
801+
}
802+
779803
/*
780804
* static void get_pnt_info
781805
*
@@ -941,7 +965,6 @@ static void log_error_info(const char *now_file,
941965
const void *start_user;
942966
unsigned int prev_line, user_size;
943967
skip_alloc_t *other_p;
944-
pnt_info_t pnt_info;
945968
int out_len, dump_size, offset;
946969

947970
if (slot_p == NULL) {
@@ -955,8 +978,7 @@ static void log_error_info(const char *now_file,
955978
prev_line = slot_p->sa_line;
956979
user_size = slot_p->sa_user_size;
957980
if (user_pnt == NULL) {
958-
get_pnt_info(slot_p, &pnt_info);
959-
start_user = pnt_info.pi_user_start;
981+
start_user = get_pnt_start(slot_p);
960982
}
961983
else {
962984
start_user = user_pnt;
@@ -2423,9 +2445,7 @@ int _dmalloc_chunk_free(const char *file, const unsigned int line,
24232445
del_p = del_p->sa_next_p[0]) {
24242446
if (del_p->sa_mem <= user_pnt
24252447
&& (char *)del_p->sa_mem + del_p->sa_total_size > (char *)user_pnt) {
2426-
pnt_info_t info;
2427-
get_pnt_info(del_p, &info);
2428-
if (info.pi_user_start == user_pnt) {
2448+
if (user_pnt == get_pnt_start(del_p)) {
24292449
dmalloc_errno = DMALLOC_ERROR_ALREADY_FREE;
24302450
}
24312451
else {
@@ -2810,7 +2830,7 @@ void _dmalloc_chunk_log_changed(const unsigned long mark,
28102830
const int log_freed_b, const int details_b)
28112831
{
28122832
skip_alloc_t *slot_p;
2813-
pnt_info_t pnt_info;
2833+
void *pnt_start;
28142834
int known_b, freed_b, used_b;
28152835
char out[DUMP_SPACE * 4], *which_str;
28162836
char where_buf[MAX_FILE_LENGTH + 64], disp_buf[64];
@@ -2901,13 +2921,13 @@ void _dmalloc_chunk_log_changed(const unsigned long mark,
29012921
known_b = 1;
29022922
}
29032923

2904-
get_pnt_info(slot_p, &pnt_info);
2924+
pnt_start = get_pnt_start(slot_p);
29052925

29062926
if (known_b || (! BIT_IS_SET(_dmalloc_flags, DMALLOC_DEBUG_LOG_KNOWN))) {
29072927
if (details_b) {
29082928
dmalloc_message(" %s freed: '%s' (%u bytes) from '%s'",
29092929
(freed_b ? " " : "not"),
2910-
display_pnt(pnt_info.pi_user_start, slot_p, disp_buf,
2930+
display_pnt(pnt_start, slot_p, disp_buf,
29112931
sizeof(disp_buf)),
29122932
slot_p->sa_user_size,
29132933
_dmalloc_chunk_desc_pnt(where_buf, sizeof(where_buf),
@@ -2916,10 +2936,10 @@ void _dmalloc_chunk_log_changed(const unsigned long mark,
29162936

29172937
if ((! freed_b)
29182938
&& BIT_IS_SET(_dmalloc_flags, DMALLOC_DEBUG_LOG_NONFREE_SPACE)) {
2919-
out_len = expand_chars((char *)pnt_info.pi_user_start, DUMP_SPACE,
2939+
out_len = expand_chars((char *)pnt_start, DUMP_SPACE,
29202940
out, sizeof(out));
29212941
dmalloc_message(" dump of '%p': '%.*s'",
2922-
pnt_info.pi_user_start, out_len, out);
2942+
pnt_start, out_len, out);
29232943
}
29242944
}
29252945
_dmalloc_table_insert(&mem_table_changed, slot_p->sa_file,

0 commit comments

Comments
 (0)