Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-1286] Incorrect memory management in PotentialArchetype::getNestedType #43894

Closed
gparker42 mannequin opened this issue Apr 22, 2016 · 3 comments
Closed

[SR-1286] Incorrect memory management in PotentialArchetype::getNestedType #43894

gparker42 mannequin opened this issue Apr 22, 2016 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself good first issue Good for newcomers

Comments

@gparker42
Copy link
Mannequin

gparker42 mannequin commented Apr 22, 2016

Previous ID SR-1286
Radar None
Original Reporter @gparker42
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, StarterBug
Assignee None
Priority Medium

md5: cd28299a77346e38defc2cc95944ee39

Issue Description:

PotentialArchetype::getNestedType() has a memory management error that causes compiler crashes.

The problem is `nested`. It is a reference into the NestedTypes collection. The recursive call to getNestedType() can modify NestedTypes, which invalidates the `nested` variable in the outer getNestedType() call.

This causes compiler_crashers/28279-swift-archetypebuilder-potentialarchetype-getnestedtype.swift

@gparker42
Copy link
Mannequin Author

gparker42 mannequin commented Apr 22, 2016

The assignment `NestedTypes[nestedName] = nested` is also suspicious. My guess is that there was some confusion about values vs references here. As I understand it, that assignment is entirely unnecessary.

@gparker42
Copy link
Mannequin Author

gparker42 mannequin commented Apr 22, 2016

Possible solutions:

1. Make the NestedTypes collection store some smart shared pointer type. That is more likely to be the right answer if there are other bugs involving NestedTypes in this code.
2. Look up NestedTypes[nestedName] locally every time it is needed instead of caching it for the entire function. That might be a performance problem but is otherwise a simpler fix if the other uses of NestedTypes look correct.

@huonw
Copy link
Mannequin

huonw mannequin commented Sep 7, 2016

This was fixed in #2415

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

0 participants