File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -177,3 +177,38 @@ class ControllableAllocator : public ArduinoJson::Allocator {
177
177
bool _enabled;
178
178
Allocator* _upstream;
179
179
};
180
+
181
+ class TimebombAllocator : public ArduinoJson ::Allocator {
182
+ public:
183
+ TimebombAllocator (
184
+ size_t initialCountdown,
185
+ Allocator* upstream = ArduinoJson::detail::DefaultAllocator::instance())
186
+ : _countdown(initialCountdown), _upstream(upstream) {}
187
+ virtual ~TimebombAllocator () {}
188
+
189
+ void * allocate (size_t n) override {
190
+ if (!_countdown)
191
+ return nullptr ;
192
+ _countdown--;
193
+ return _upstream->allocate (n);
194
+ }
195
+
196
+ void deallocate (void * p) override {
197
+ _upstream->deallocate (p);
198
+ }
199
+
200
+ void * reallocate (void * ptr, size_t n) override {
201
+ if (!_countdown)
202
+ return nullptr ;
203
+ _countdown--;
204
+ return _upstream->reallocate (ptr, n);
205
+ }
206
+
207
+ void setCountdown (size_t value) {
208
+ _countdown = value;
209
+ }
210
+
211
+ private:
212
+ size_t _countdown = 0 ;
213
+ Allocator* _upstream;
214
+ };
You can’t perform that action at this time.
0 commit comments