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

fix: avoid stack overflow with std::unique_ptr linked list #2366

Merged
merged 1 commit into from
Apr 7, 2023

Conversation

ianna
Copy link
Collaborator

@ianna ianna commented Apr 6, 2023

No description provided.

@ianna ianna requested a review from jpivarski April 6, 2023 08:28
@codecov
Copy link

codecov bot commented Apr 6, 2023

Codecov Report

Merging #2366 (2749c22) into main (29f89d8) will not change coverage.
The diff coverage is n/a.

Additional details and impacted files

@ianna ianna temporarily deployed to docs-preview April 6, 2023 08:51 — with GitHub Actions Inactive
Copy link
Member

@jpivarski jpivarski left a comment

Choose a reason for hiding this comment

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

I don't know enough modern C++ to be sure that this is right, but it is a for loop, rather than recursion.

The loop termination I understand, though I would have written current; as current != nullptr; for clarity.

I don't see how current = std::move(current->next_) deletes what current is pointing to and sets it to the value of current->next_. This must use some properties of std::unique_ptr somehow...

But it clearly looks like it's addressing the issue with an explicit for loop and if you're not getting giant memory leaks in your billion-value tests, then it must be deleting those panels.

@ianna
Copy link
Collaborator Author

ianna commented Apr 7, 2023

I don't know enough modern C++ to be sure that this is right, but it is a for loop, rather than recursion.

The loop termination I understand, though I would have written current; as current != nullptr; for clarity.

I don't see how current = std::move(current->next_) deletes what current is pointing to and sets it to the value of current->next_. This must use some properties of std::unique_ptr somehow...

The move transfers ownership and nulls it, please, see 20.8.1 in https://isocpp.org/files/papers/n4296.pdf

But it clearly looks like it's addressing the issue with an explicit for loop and if you're not getting giant memory leaks in your billion-value tests, then it must be deleting those panels.

The recursion is gone :-) Please, see a partially expanded stack before the change:
Screenshot 2023-04-07 at 10 34 50
and a fully expanded one after:
Screenshot 2023-04-07 at 10 36 40

@jpivarski
Copy link
Member

Okay, good explanation! I'll merge it now.

@jpivarski jpivarski merged commit 01417bc into main Apr 7, 2023
@jpivarski jpivarski deleted the ianna/growablebuffer-update-algo branch April 7, 2023 12:48
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