Skip to content

Fix memory handling and terminology in UnorderedList section - #1161

Merged
pearcej merged 2 commits into
pearcej:masterfrom
wrigjl:fix-unordered-list-memory
Oct 13, 2026
Merged

pearcej merged 2 commits into
pearcej:masterfrom
wrigjl:fix-unordered-list-memory

Conversation

@wrigjl

@wrigjl wrigjl commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator

Fixes in pretext/LinearLinked/UnorderedListClass.ptx (§4 unordered linked list).

Bugs

  • remove unlinked the node but never freed it, so every call leaked one node. Both the listing and the full program now delete current; after relinking, and a new paragraph explains why.
  • The full program never freed its list. Added ~UnorderedList() as its own listing with an explanation (save next before deleting), added it to the full program, and noted briefly that copying a list is now unsafe.

Text that contradicted the code

  • The search prose described a found flag that the code doesn't have. It now says search returns true immediately.
  • Several places called pointers "references", which is Python terminology and wrong for C++, where references are a different thing. These now say "pointer". Uses of "refer to" as a verb are unchanged.
  • The remove prose's line numbers were off by one (12/13/15 → 13/14/16), and it used a Python-style current.getNext().
  • The Node constructor comment no longer says the data is "set as the head".
  • Typo: "statment" → "statement".

Testing
I extracted the full ActiveCode program and compiled it with clang++ (C++17, -Wall -Wextra -fsanitize=undefined). Under leaks --atExit, the original leaks 7 nodes and this version leaks 0. Program output is unchanged. xmllint passes. I have not done a full PreTeXt build locally.

One more PR is coming for each remaining Chapter 4 file (ordered list, Node class, ordered list ADT), plus one for the prefix glossary entry in Chapter 3.

🤖 Generated with Claude Code

wrigjl and others added 2 commits October 12, 2026 15:56
- remove: delete the unlinked node (it leaked on every call), with
  prose explaining why
- Add an UnorderedList destructor, as a listing with explanation and
  in the full program; note that copying a list is unsafe
- search: prose described a `found` flag the code doesn't have
- Call pointers "pointers", not "references" (C++ references are a
  different thing)
- Node constructor comment no longer says the data is "the head"
- Fix off-by-one line numbers in the remove prose and a Python-style
  `current.getNext()`

Full program verified with `leaks --atExit`: 7 leaked nodes before,
0 after; output unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@pearcej pearcej left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great work.

@pearcej
pearcej merged commit 08c44eb into pearcej:master Oct 13, 2026
2 checks passed
@wrigjl
wrigjl deleted the fix-unordered-list-memory branch October 13, 2026 21:19
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.

2 participants