Throw exceptions by value, not by pointer - #42
Open
Sheephog wants to merge 1 commit into
Open
Conversation
Five sites threw a pointer to an exception rather than the exception itself. catch (const std::exception&) does not match std::invalid_argument*, and nothing in the tree catches by pointer, so these throws bypassed every handler, unwound to std::terminate() -- a reboot on ESP32 -- and leaked the allocation. Inherited from the vendored microReticulum snapshot (attermann 0.2.4); attermann fixed this in 0.4.0.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Five sites throw a pointer to an exception rather than the exception itself:
lib/microReticulum/src/Cryptography/Token.cpp(2 sites, inencryptanddecrypt)lib/microReticulum/src/Cryptography/Token.h(generate_key)lib/microReticulum/src/Link.cpp(2 sites)catch (const std::exception&)does not matchstd::invalid_argument*, and nothing in the tree catches by pointer. So when one of these fires it bypasses every handler, unwinds tostd::terminate()— which on ESP32 is a device reboot — and leaks the allocation on the way out.Origin
This is inherited rather than recent: the same form is present in the vendored microReticulum snapshot this fork is based on (attermann 0.2.4, which has
throw newat these sites). Upstream attermann fixed it in 0.4.0; this fork predates that re-vendor and still carries the older form.Solution
throw new X(...)→throw X(...)at all five sites. No behaviour change on any non-error path — the only difference is that these errors can now actually be caught.Compatibility: nothing is affected. I checked the tree for
catchclauses taking a pointer type and there are none, so no existing handler depended on the old behaviour.Testing: compiled and running on 3 × Heltec V4 (ESP32-S3). No fault has been attributed to this change.
Found while porting upstream microReticulum changes into my fork. Like this project, my fork is developed with AI assistance under human direction — I've reviewed this change, and it's running on hardware as above.