AmendHub

jcs

/

subtext

/

amendments

/

util.c

Amendments on February 16, 2024

util: Make xalloc tables dynamically allocated

Also reduce err_str size
jcs made amendment 593 2 months ago

Amendments on February 15, 2024

util: Add dynamic malloc tracking

The previous malloc note stuff was removed since it required every
xmalloc call to include a string, which was laborious to use and
added a lot of code and memory space having to store all those
strings.
Now when MALLOC_DEBUG is defined, the stack is walked to find the
symbols of each function along the way to xmalloc and pointers to
elements of the symbol table are stored, minimizing the amount of
strings that need to be stored in memory, and providing a way to see
the full stack trace of each allocation with xalloc_print. We can
also check in xfree that the allocation was still in our list to
avoid a double free or a junk free.
jcs made amendment 587 2 months ago

Amendments on February 1, 2024


Amendments on January 24, 2024

util: Don't include resource fork length in FStat st_size

This is usually used to figure out how big a file is to allocate a
buffer of that size and then FSRead it, but if we're including the
resource fork length, we'll do what appears to be a short read.
jcs made amendment 581 3 months ago

Amendments on April 10, 2023


Amendments on March 27, 2023


Amendments on March 26, 2023

util: No longer warn() when xmalloc fails, callers handle it now

Also panic when xfree() is called on a pointer to NULL, it's never ok.
jcs made amendment 448 about 1 year ago

Amendments on March 8, 2023

util: Remove unused variable

jcs made amendment 381 about 1 year ago

Amendments on March 2, 2023

util: Turn EXPAND_TO_FIT into grow_to_fit function

This will return false if the xrealloc failed, leaving the original
pointer untouched. With the macro, the pointer would get overwritten
with NULL and not be able to be freed.
jcs made amendment 332 about 1 year ago

Amendments on March 1, 2023

util: Make x* allocation functions no longer fatal on failure

Display a warning, but return NULL
Also remove MALLOC_DEBUG, it is not as helpful as I wanted and just
bloats things having to store all these note strings
jcs made amendment 331 about 1 year ago

Amendments on February 5, 2023

*: Minor fixes found by cppcheck and scan-build

Mostly unused variables
jcs made amendment 300 about 1 year ago

Amendments on September 16, 2022

util: panic on xfree(NULL) and xfree(&NULL)

jcs made amendment 252 about 1 year ago

Amendments on September 13, 2022

util: Fix ask DITL that mistakenly got replaced

jcs made amendment 249 about 1 year ago

Amendments on September 8, 2022

util: Sync with upstream

jcs made amendment 246 about 1 year ago

Amendments on August 3, 2022

util: Support malloc map compaction by toggling a variable

jcs made amendment 227 about 1 year ago

Amendments on July 31, 2022

util: Add note parameter to xmalloc, xcalloc, and xrealloc

If THINK C supported __func__ this would be much easier, but for now
we have to manually annotate every allocation. This will help find
the source of memory leaks.
jcs made amendment 224 about 1 year ago

Amendments on July 21, 2022

*: Use NewPtr instead of malloc, add malloc and free debugging

Instead of free(ptr), use xfree(&ptr) and after it calls
DisposePtr(ptr), it will update ptr to point at NULL to catch
use-after-frees.
When MALLOC_DEBUG is defined, each allocation is added to a
list, and removed when freed. If it's not in the list at free
time, it's a double-free. Also, instead of pointing pointers at
NULL, point them to a pre-defined block of zeroes and in the
idle loop, periodically check that this block is still zero. This
will also catch use-after-frees in a more reliable (but costly)
way.
jcs made amendment 220 about 1 year ago

Amendments on July 16, 2022

*: Move some big char buffers from the stack to the heap

Use FILENAME_MAX in place of 256 where appropriate.
jcs made amendment 209 about 1 year ago

Amendments on July 12, 2022

board+folder+mail: Trim trailing whitespace from fields

jcs made amendment 199 about 1 year ago