fix(eo): fix null pointer and dangling pointer bugs in eoForge#89
Open
evvaletov wants to merge 1 commit intonojhan:masterfrom
Open
fix(eo): fix null pointer and dangling pointer bugs in eoForge#89evvaletov wants to merge 1 commit intonojhan:masterfrom
evvaletov wants to merge 1 commit intonojhan:masterfrom
Conversation
eoForgeOperator no-arg specialization: instantiate_ptr() constructed an empty shared_ptr instead of a new Op instance, always returning nullptr. Fix: std::shared_ptr<Op>() → std::make_shared<Op>(). eoForgeMap::setup(): after deleting the old operator, emplace() silently no-ops when the key already exists, leaving a dangling pointer in the map and leaking the new allocation. Fix: assign through at() instead.
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.
Summary
Two bugs in
eo/src/eoForge.h:1.
eoForgeOperatorno-arg specialization:instantiate_ptr()returns nullThe partial specialization for constructors without arguments (line 206)
constructs an empty
shared_ptrinstead of allocating a newOp:The full-args overload correctly uses
std::make_shared<Op>(...)viaop_constructor_ptr, so this is an inconsistency in the no-argspecialization.
2.
eoForgeMap::setup(): dangling pointer and memory leakAfter
delete this->at(name), the key remains in the map pointing tofreed memory.
std::map::emplacedoes not insert when the key alreadyexists, so:
pfoleaksBoth
setup()overloads (with-args and no-args) had the same bug.Note that
eoForgeVector::setup()already does this correctly viathis->at(index) = pfo.Changes
eo/src/eoForge.hTest plan
t-operator-forge