Repository navigation
Commit cf01af5
sqllogictest: account before alloc to avoid panic-after-alloc hazards (apache#22742)
## Which issue does this PR close?
- Closes #.
Follow-up defect fix in the allocator-level accounting framework added
by apache#22626.
## Rationale for this change
`AccountingAllocator::realloc` (introduced in apache#22626) called
`inner.realloc` first — which frees the caller's old pointer on success
— then called `track`, which can `panic_any` on overdraft. The unwind
starts with the caller's `Vec` (or similar growing container) still
holding the now-freed old pointer; the next `Drop` produces glibc's
`double free or corruption (out)` and SIGABRT, masking the underlying
untracked-allocation panic the framework was trying to surface.
The same hazard does not apply to `alloc` / `alloc_zeroed` / `dealloc`:
- `alloc` / `alloc_zeroed` — the caller has no preexisting pointer to be
invalidated; panicking after the inner alloc just leaks the new
allocation, which is fine on the kill path.
- `dealloc` — credits the bank, never panics.
Only `realloc` has a live caller-side pointer that gets invalidated by
the inner operation before the panic decision.
## What changes are included in this PR?
Reorder `AccountingAllocator::realloc` to account first, forward to
`inner.realloc` second:
- `track(delta)` first — on overdraft we panic with the caller's pointer
still valid; unwind drops the live container cleanly, no abort.
- If `inner.realloc` returns null after a successful track, refund the
delta so the bank stays consistent with what actually got allocated.
## Are these changes tested?
Manually verified using a `GroupedHashAggregateStream` + `List<Utf8>`
group-key reproducer (routes through `GroupValuesRows::intern` →
`RowConverter::append` → `Vec::resize` → `__rust_realloc`, which is one
of the untracked-allocation sites this framework is meant to catch):
- before: exit 101, `double free or corruption (out)`, signal 6 SIGABRT
- after: exit 1, clean `allocator overdraft: account balance at panic =
-1.7 MB` at the same `RowConverter::append` stack frame
A regression test for "panic from inside `realloc` does not double-free"
would require constructing the precise realloc-mid-grow scenario plus a
`catch_unwind` harness; deferred as follow-up.
## Are there any user-facing changes?
No. Confined to `sqllogictest`'s `memory-accounting` feature, which is
internal CI tooling.
Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>1 parent d88ab6a commit cf01af5
1 file changed
Lines changed: 26 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
276 | 276 | | |
277 | 277 | | |
278 | 278 | | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
279 | 285 | | |
280 | 286 | | |
281 | | - | |
282 | | - | |
283 | | - | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
284 | 290 | | |
285 | 291 | | |
286 | 292 | | |
287 | 293 | | |
288 | 294 | | |
289 | 295 | | |
290 | 296 | | |
291 | | - | |
| 297 | + | |
| 298 | + | |
292 | 299 | | |
293 | 300 | | |
294 | 301 | | |
295 | 302 | | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
296 | 306 | | |
297 | 307 | | |
298 | | - | |
299 | | - | |
| 308 | + | |
| 309 | + | |
300 | 310 | | |
301 | 311 | | |
302 | 312 | | |
303 | 313 | | |
304 | 314 | | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
305 | 322 | | |
306 | 323 | | |
307 | | - | |
308 | | - | |
309 | | - | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
310 | 327 | | |
311 | 328 | | |
312 | 329 | | |
| |||
0 commit comments