File tree Expand file tree Collapse file tree 3 files changed +15
-14
lines changed Expand file tree Collapse file tree 3 files changed +15
-14
lines changed Original file line number Diff line number Diff line change 1
1
ArduinoJson: change log
2
2
=======================
3
3
4
+ HEAD
5
+ ----
6
+
7
+ * Fixed ` DynamicJsonBuffer::clear() ` not resetting allocation size (issue #561 )
8
+
4
9
v5.11.1
5
10
-------
6
11
Original file line number Diff line number Diff line change @@ -52,7 +52,7 @@ class DynamicJsonBufferBase
52
52
: _head(NULL ), _nextBlockCapacity(initialSize) {}
53
53
54
54
~DynamicJsonBufferBase () {
55
- freeAllBlocks ();
55
+ clear ();
56
56
}
57
57
58
58
// Gets the number of bytes occupied in the buffer
@@ -71,7 +71,13 @@ class DynamicJsonBufferBase
71
71
// Resets the buffer.
72
72
// USE WITH CAUTION: this invalidates all previously allocated data
73
73
void clear () {
74
- freeAllBlocks ();
74
+ Block* currentBlock = _head;
75
+ while (currentBlock != NULL ) {
76
+ _nextBlockCapacity = currentBlock->capacity ;
77
+ Block* nextBlock = currentBlock->next ;
78
+ _allocator.deallocate (currentBlock);
79
+ currentBlock = nextBlock;
80
+ }
75
81
_head = 0 ;
76
82
}
77
83
@@ -144,16 +150,6 @@ class DynamicJsonBufferBase
144
150
return true ;
145
151
}
146
152
147
- void freeAllBlocks () {
148
- Block* currentBlock = _head;
149
-
150
- while (currentBlock != NULL ) {
151
- Block* nextBlock = currentBlock->next ;
152
- _allocator.deallocate (currentBlock);
153
- currentBlock = nextBlock;
154
- }
155
- }
156
-
157
153
TAllocator _allocator;
158
154
Block* _head;
159
155
size_t _nextBlockCapacity;
Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ TEST_CASE("DynamicJsonBuffer::alloc()") {
46
46
REQUIRE (allocatorLog.str () == " A1A2FF" );
47
47
}
48
48
49
- SECTION (" Keeps increasing allocation size after clear" ) {
49
+ SECTION (" Resets allocation size after clear() " ) {
50
50
allocatorLog.str (" " );
51
51
{
52
52
DynamicJsonBufferBase<SpyingAllocator> buffer (1 );
@@ -55,7 +55,7 @@ TEST_CASE("DynamicJsonBuffer::alloc()") {
55
55
buffer.clear ();
56
56
buffer.alloc (1 );
57
57
}
58
- REQUIRE (allocatorLog.str () == " A1A2FFA4F " );
58
+ REQUIRE (allocatorLog.str () == " A1A2FFA1F " );
59
59
}
60
60
61
61
SECTION (" Makes a big allocation when needed" ) {
You can’t perform that action at this time.
0 commit comments