Skip to content

Commit f816fa1

Browse files
committed
1
1 parent 5143689 commit f816fa1

File tree

3 files changed

+53
-10
lines changed

3 files changed

+53
-10
lines changed

cc/cc/cc/allocator/cc_simple_segregated_storage_dump.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,12 @@ cc_api void cc_simple_segregated_storage_dump(cc_simple_segregated_storage_t* si
7979

8080

8181
printf(
82-
"- free_chunk [%3lld] = %p(%4lld): index=%3lld, next_free_chunk = %3lld : %p(%4lld)\n",
82+
"- free_chunk [%3lld] = %p(%4lld)[%3lld] : next_free_chunk = %p(%4lld)[%3lld] \n",
8383
(int64_t)free_chunk_count,
84-
(void*)free_chunk, cc_offset_address(free_chunk, base_address),
85-
(int64_t)free_chunk_index, (int64_t)free_chunk_next_index,
86-
(void*)free_chunk->next_free_chunk, cc_offset_address(free_chunk->next_free_chunk, base_address)
84+
(void*)free_chunk, cc_offset_address(free_chunk, base_address),
85+
(int64_t)free_chunk_index,
86+
(void*)free_chunk->next_free_chunk, cc_offset_address(free_chunk->next_free_chunk, base_address),
87+
(int64_t)free_chunk_next_index
8788
);
8889

8990
free_chunk_count++;

cc/cc/cc/dynamic/cc_first_fit_dump.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,13 @@ cc_api void cc_first_fit_dump(cc_first_fit_t* first_fit, size_t number, uintptr_
108108

109109

110110
printf(
111-
"- block[%3lld] = %p(%4lld): pointer = %p(%4lld) size = %6lld bytes %s \n",
111+
"- block[%3lld] = %p(%4lld) size = %6lld bytes : pointer = %p(%4lld) %s \n",
112112
(int64_t)block_count,
113113
(void*)block, cc_offset_address(block, base_address),
114-
(void*)(address), cc_offset_address((void*)(address), base_address),
115114
(int64_t)block_size,
115+
(void*)(address), cc_offset_address((void*)(address), base_address),
116116
(block_is_allocated ? "allocated" : "free ")
117-
);
117+
);
118118

119119

120120
block = (cc_first_fit_block_head_t*)(block_address + block_size);

cc/cc/test_cc/test_case_cc_string_1.cpp

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@
88

99
/////////////////////////////////////////////////////////////////////////////
1010
//===========================================================================
11+
static inline size_t cc_string_allocated_size(cc_string_t* s)
12+
{
13+
size_t current = 1;
14+
15+
16+
while (current < (s->capacity))
17+
current <<= 1;
18+
return current;
19+
}
20+
1121
static void string_append(bool memory_leack)
1222
{
1323
test_out
@@ -17,15 +27,17 @@ static void string_append(bool memory_leack)
1727

1828

1929
cc_string_t s;
30+
cc_string_t s0;
31+
cc_string_t s1;
32+
33+
2034
cc_string_create(&s, cc_default_string_heap_memory_allocator());
2135
cc_string_append(&s, "Hello");
2236

2337

2438

25-
cc_string_t s0;
2639
cc_string_create(&s0, cc_default_string_heap_memory_allocator());
2740

28-
cc_string_t s1;
2941
cc_string_create(&s1, cc_default_string_heap_memory_allocator());
3042
cc_string_append(&s1, "<Hello");
3143
cc_string_append(&s1, "World>");
@@ -35,7 +47,7 @@ static void string_append(bool memory_leack)
3547
cc_string_append(&s1, "<World>");
3648

3749

38-
for (size_t i = 0; i < 10; i++)
50+
for (size_t i = 0; i < 20; i++)
3951
{
4052
cc_string_append(&s0, cc_string_c_str(&s1));
4153
test_out
@@ -46,15 +58,45 @@ static void string_append(bool memory_leack)
4658
;
4759
}
4860

61+
4962
if (memory_leack == false)
5063
{
5164
cc_string_destroy(&s1);
5265
}
66+
else
67+
{
68+
test_out << "Memory Leak Test: Skip cc_string_destroy(&s1)" << test_tendl;
69+
}
5370

5471
test_out << "s0: data=" << cc_string_c_str(&s0) << test_tendl;
5572

5673

5774

75+
if (memory_leack == false)
76+
{
77+
cc_string_destroy(&s0);
78+
}
79+
else
80+
{
81+
size_t alignment = sizeof(void*) * 2;
82+
size_t s0_string_memory_size = s0.capacity + 1;
83+
size_t s0_string_memory_aligned_size =
84+
s0_string_memory_size / alignment * alignment + ((s0_string_memory_size % alignment) ? alignment : 0);
85+
86+
size_t s0_memory_leak_size =
87+
sizeof(cc_first_fit_block_head_t) +
88+
s0_string_memory_aligned_size;
89+
;
90+
91+
uintptr_t s0_address = (uintptr_t)&s0.data[0];
92+
93+
test_out << "Memory Leak Test: Skip cc_string_destroy(&s0):"
94+
<< " s0_memory_leak_size=" << s0_memory_leak_size
95+
<< " s0.data =" << (void*)s0_address
96+
<< test_tendl;
97+
}
98+
99+
58100
if (memory_leack == false)
59101
{
60102
cc_string_destroy(&s);

0 commit comments

Comments
 (0)