Skip to content

Fix danging pointer and leak in FTR#7

Open
ripopov wants to merge 1 commit intoMinres:mainfrom
ripopov:ftr-fixes
Open

Fix danging pointer and leak in FTR#7
ripopov wants to merge 1 commit intoMinres:mainfrom
ripopov:ftr-fixes

Conversation

@ripopov
Copy link
Contributor

@ripopov ripopov commented Dec 17, 2025

Issue 1: ftr::dictionary can cause segfault on use-after-free

  • When a new string is added, it's stored in out_dict via push_back()
  • A raw pointer from out_dict.back().c_str() is inserted into lut
  • When out_dict grows and reallocates its internal storage, all previously stored c_str() pointers become dangling

Replaced with deque ( deque guarantees pointers are not invalidated on push_back)

Issue 2: Memory leak in ftr_writer destructor (entry pool)

Each tx_entry contains an encoder<memory_writer> which has a std::vector<uint8_t> buffer. When free() is called on the raw memory block, these vectors are never destructed, leaking their heap-allocated storage

Also replaced with deque to automatically call destructors

Issue 1: ftr::dictionary can cause segfault when long strings are added to dictionary

- When a new string is added, it's stored in out_dict via push_back()
- A raw pointer from out_dict.back().c_str() is inserted into lut
- When out_dict grows and reallocates its internal storage, all previously stored c_str() pointers become dangling

Issue 2: Memory leak in ftr_writer destructor (entry pool)

Each tx_entry contains an encoder<memory_writer> which has a std::vector<uint8_t> buffer.
When free() is called on the raw memory block, these vectors are never destructed, leaking their heap-allocated storage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant